'use strict';
(function (exports) {
    exports.MaRoomHuNan = cc.Layer.extendEX({
        isCCSLoadFinished: false,
        enableChupaiCnt: 0,
        roomData: null,
        isReconnect: null,
        isReplay: null,
        mapId: null,
        uid: null,
        //房间状态
        roomStateType: {
            ROOM_STATE_CREATED: 1,
            ROOM_STATE_ONGOING: 2,
            ROOM_STATE_ENDED: 3
        },
        roomStatus: {
            CREATED: 1,  // 刚创建
            PREPARING: 5,// 准备阶段
            ONGING: 2,   // 正在游戏
            GAMEOVER: 3, // 游戏结束
            ENDED: 4     // 房间解散
        },
        roomState: 2,
        //玩家数据
        playerNums: 4,
        isCanSitdown: false,
        roomPlayers: {},
        uid2position: {},
        uid2playerInfo: {},
        position2uid: {},
        position2sex: {},
        position2playerArrIdx: {},
        //坐标配置
        posConf: {
            headPosBak: {}
            , paiA0PosBak: {}
            , paiA0ScaleBak: {}
            , paiADistance: []

            , paiALiangDistance: [0.5, 3.5, 0, -3.5]
            , paiMopaiDistance: {0: 16, 1: 40, 2: 34, 3: 40}
            , paiGDistance: []
            , paiUsedDistance: []
            , paiUsedZOrder: {
                0: {0: -1, 10: 0, 20: 1, 30: 2, 40: 3, 50: 4}
                , 1: {0: -1, 10: -1, 20: -1, 30: -1, 40: -1, 50: -1}
                , 2: {0: 0, 10: -1, 20: -2, 30: -3, 40: -3, 50: -4}
                , 3: {0: 0, 10: 1, 20: 2, 30: 3, 40: 4, 50: 5}
            }
            , cpghgPositionX: {
                2: [660, 920],
                3: [425, 700, 960],
                4: [320, 580, 840, 1070],
                5: [210, 460, 700, 940, 1130],
                6: [210, 460, 700, 940, {x: 700, y: 360}, 1180]
            }
            , upPaiPositionY: null
            , downPaiPositionY: null

            , groupG0PosBak: {}
            , groupWidth: {}
            , groupHeight: {}
            , groupDistance: {0: 4, 1: -10, 2: 16, 3: -10}
            , groupToFirstPaiDistance: {0: 10, 1: -24, 2: 26, 3: -24}

            , paiPos: {}
            , gPaiPos: {
                0: {1: 0, 2: 1, 3: 2},
                1: {0: 2, 2: 0, 3: 1},
                2: {0: 1, 3: 0, 1: 2},
                3: {0: 0, 1: 1, 2: 2}
            }
            , huFromAngle: [
                180,
                270,
                0,
                90
            ]
            , fromPos: [
                {x: 30, y: 85},
                {x: 70, y: 40},
                {x: 30, y: 20},
                {x: 10, y: 40}
            ]
        },

        PAINAMES: ["", "一万", "二万", "三万", "四万", "五万", "六万", "七万", "八万", "九万",
            "一条", "二条", "三条", "四条", "五条", "六条", "七条", "八条", "九条",
            "一筒", "二筒", "三筒", "四筒", "五筒", "六筒", "七筒", "八筒", "九筒"],
        ORIENTATION: {
            0: '东',
            1: '南',
            2: '西',
            3: '北'
        },
        UP_PAI_TIME: 0.02,
        FAPAI_ANIM_DELAY: 0.04,
        FAPAI_ANIM_DURATION: 0.2,
        MOPAI_ANIM_DURATION: 0.3,
        UPDOWNPAI_ANIM_DURATION: 0.088,
        UPPAI_Y: 30,
        opType: {
            OP_CHI: 1,
            OP_PENG: 2,
            OP_GANG: 3,
            OP_HU: 4,
            OP_PASS: 5,
            OP_TING: 6,
            OP_LIANG: 7,
            OP_JIA: 8,
            OP_DIAO: 9,
            OP_DUIDAO: 10,
            OP_BIAN: 11,
            OP_KAIGANG: 50,
            OP_XIAOHU: 51,

            OP_BU: 6,
            OP_FEI: 8,
            OP_TI: 9,
        },
        hasChupai: false,
        turnRow: null,
        leftPaiCnt: 0,
        lianging: false,

        liangPai: 0,
        liangPaiIdx: 0,
        liangStep: 0,

        position2que: {},
        position2quelr: {},
        isHuansanzhanging: false,
        isDingQue: false,

        hideGangStep: 0,
        hideGangArr: [],
        hidedGangArr: [],
        hideGangChupaiArr: [],
        hupaiMap: {},

        afterLianging: false,
        disabledChuPaiIdMap: {},
        disableChupai: false,
        selectingXiaohu: false,
        curHuPaiId: 0,

        bShowVideo: false,
        allCache: null,
        beforeOnCCSLoadFinish: null,
        afterGameStart: null,

        laiziPaiId: 0,
        laizipiPaiAId: 0,
        laizipiPaiBId: 0,

        clickTing: false,
        isTingData: 0,
        hideTing: [],

        curPaiArr: null,//当前手牌数组 客户端存
        prePaiArr: null,//临时手牌 用于亮牌


        chiLayer: null,
        throwDiceLayer: null,
        kaigangLayer: null,

        pos0: null,
        pos1: null,
        pos2: null,
        pos3: null,
        getPaiNameByRowAndId: function (row, id, isLittle, isStand) {
            var prefix;
            var ret = null;
            if (row == 0 && isLittle) prefix = "p0s";
            if (row == 0 && !isLittle) prefix = "p2l";
            if (row == 1 && isLittle) prefix = "p1s";
            if (row == 1 && !isLittle) prefix = "p2l";
            if (row == 2 && isLittle) prefix = "p2s";
            if (row == 2 && !isLittle) prefix = "p2l";
            if (row == 3 && isLittle) prefix = "p3s";
            if (row == 3 && !isLittle) prefix = "p2l";

            if (prefix) ret = prefix + id + '.png';

            if (row == 0 && id == 0 && isLittle) ret = 'p0s0' + '.png';
            if (row == 1 && id == 0 && isLittle) ret = 'p1s0' + '.png';
            //if (row == 2 && id == 0 && isLittle) ret = '' + '.png';
            if (row == 3 && id == 0 && isLittle) ret = 'p3s0' + '.png';
            //if (row == 0 && id == 0 && !isLittle) ret = 'bs' + '.png';
            //if (row == 1 && id == 0 && !isLittle) ret = 'bh' + '.png';
            if (row == 2 && id == 0 && !isLittle) ret = 'p2l0' + '.png';
            //if (row == 3 && id == 0 && !isLittle) ret = 'bh' + '.png';

            if (row == 0 && isStand && isLittle) ret = 'h0s' + '.png';
            if (row == 1 && isStand && isLittle) ret = 'h1s' + '.png';
            if (row == 3 && isStand && isLittle) ret = 'h3s' + '.png';
            if (row == 0 && isStand && !isLittle) ret = 'p2l0' + '.png';
            if (row == 1 && isStand && !isLittle) ret = 'by' + '.png';
            if (row == 3 && isStand && !isLittle) ret = 'bz' + '.png';

            return ret;
        },
        setSpriteFrameByName: function (pai, paiName) {
            setSpriteFrameByName(pai, paiName, majiang_hn.res.pai_hn_plist);
        },
        addListener: function (code, listener) {
            network.addListener(code, listener, this);
        },
        onEnter: function () {
            var that = this;
            cc.Layer.prototype.onEnter.call(this);
            /**
             * 结算准备
             * @protected
             */
            eventManager.addListener(EventKey.ReceiveJieSuanReady, this.onJiesuanClose.bind(this));
            /**
             * 查看总结算
             * @protected
             */
            eventManager.addListener(EventKey.ReceiveZongJieSuan, this.zongJiesuan.bind(this));
            /**
             * 切换牌桌
             * @protected
             */
            eventManager.addListener(EventKey.ChangeTable, this.initBG.bind(this), this);
            /**
             * 切换音乐
             */
            eventManager.addListener(EventKey.ChangeBgm, this.changeBgm.bind(this), this);
            getVersion(app.sub_module.MaJiang_hn);


            //切入切出
            cc.eventManager.addCustomListener("game_on_hide", this.Game_On_Hide.bind(this));
            cc.eventManager.addCustomListener("game_on_show", this.Game_On_Show.bind(this));
        },
        Game_On_Hide: function () {
            network.send(3008, {room_id: gameData.roomId, voice: '', type: 'user_leave', content: '有事离开，等我一下'});
        },
        Game_On_Show: function () {
            network.send(3008, {room_id: gameData.roomId, voice: '', type: 'user_leave', content: '我回来了'});
        },
        getRootNode: function () {
            var that = this;
            return this.getChildByName("Scene");
        },
        initExtraMapData: function (data) {
            var that = this;
        },
        /**
         * 添加自己的回放Layer
         * @private
         */
        addPlayBackLayer: function () {
            var that = this;
            if (that.isReplay) {
                var ccsPlayBackUnit = majiang_hn.res.Ma_PlayBackUnit_json;
                if (gameData.mapId == app.map_id.CHANGSHA) {
                    ccsPlayBackUnit = majiang_hn.res.Ma_PlayBackUnit_changsha_json;
                }
                var playBackUnit = loadNodeCCSItem(ccsPlayBackUnit);
                for (var i = 0; i < 4; i++) {
                    var node = playBackUnit.getChildByName('root').getChildByName('cpghRep' + i);
                    node.setVisible(false);
                    node.removeFromParent(false);
                    that.getRootNode().addChild(node, 11);
                }
                showWindow('Ma_PlayBackWindow', that.roomData, that);
            }
        },
        initializeUI: function () {
            var that = this;
            that.hideSelectedPiao();
            this.hideControlBtns();
            var arr = decodeURIComponent(gameData.wanfaDesp).split(',');
            that.$('lb_wanfaName').setString(arr[0]);
            if (arr.length >= 1)
                arr = arr.slice(1);
            var wanfaStr = arr.join(",");
            that.$('lb_roomid').setString(gameData.roomId);
            that.$('lb_wanfa').setString(wanfaStr);
        },
        onCCSLoadFinish: function () {
            var that = this;
            addCachedCCSChildrenTo(majiang_hn.res.MaRoomHuNan1_json, this);
            batchSetChildrenZorder(this.getRootNode(), {
                info0: 1, info1: 1, info2: 1, info3: 1,
                info_n0: 2, info_n1: 2, info_n2: 20, info_n3: 2,
                row2: 10,
                cpghg: 11, piao_bar: 12,
                btn_bg: 30, btn_control_btns: 34,
                hu_type_layer: 99,

            });

            that.addPlayBackLayer();
            that.$ = create$(this.getRootNode());

            this.getPai = this.getPai();
            this.getGPai = this.getGPai();
            this.addUsedPai = this.addUsedPai();
            this.countDown = this.countDown();

            this.initializeUI();
            this.calcPosConf();
            this.initBG();
            this.initLog();
            MicLayer.init(that.$('btn_mic'), this);

            if (that.isReconnect) {
                gameData.zhuangUid = that.roomData['zhuang_uid'];
                gameData.leftRound = that.roomData['left_round'];
                gameData.players = that.roomData['players'];
                gameData.wanfaDesp = that.roomData['desp'];

                var status = that.roomData['room_status'] || that.roomStateType.ROOM_STATE_ONGOING;
                if (status == that.roomStateType.ROOM_STATE_ENDED) {
                    this.setRoomState(that.roomStateType.ROOM_STATE_ONGOING);
                    this.setRoomState(that.roomStateType.ROOM_STATE_ENDED);
                }
                else {
                    this.setRoomState(status);
                }

                this.initExtraMapData(that.roomData);
            }
            else
                this.setRoomState(that.roomStateType.ROOM_STATE_CREATED);


            this.clearTable4StartGame(that.isReconnect, that.isReconnect, that.roomData);

            this.startTime();

            this.startSignal();

            TouchUtil.setOnclickListener(that.$('btn_control_btns'), function () {
                that.changeBtnStatus();
            });
            TouchUtil.setOnclickListener(that.$('btn_bg'), function () {

            });
            TouchUtil.setOnclickListener(that.$('bgPanel'), function () {
                that.hideControlBtns();
            });

            TouchUtil.setOnclickListener(that.$('btn_chat'), function () {
                showWindow('ChatWindow');
            });

            TouchUtil.setOnclickListener(that.$('btn_bg.btn_setting'), function () {
                showWindow('SettingWindow', Setting_TYPE.Table_Mj);
            });

            TouchUtil.setOnclickListener(that.$('btn_zhunbei'), function () {
                network.send(3004, {room_id: gameData.roomId});
            });

            TouchUtil.setOnclickListener(that.$('btn_yxks'), function () {
                network.send(3004, {room_id: gameData.roomId});
            });

            TouchUtil.setOnclickListener(that.$('btn_invite'), function () {
                ShareUtil.ShareRoomId(gameData.roomId, gameData.wanfaDesp, gameData.playerNum, gameData.players.length);
            });

            TouchUtil.setOnclickListener(that.$('btn_copy'), function () {
                ShareUtil.CopyRoomId();
            });

            TouchUtil.setOnclickListener(that.$('btn_safe'), function () {
                showWindow('PlayerInfoLocationWindow', false, that);
            });

            TouchUtil.setOnclickListener(that.$('btn_shuaxin'), function () {
                network.disconnect();
            });

            TouchUtil.setOnclickListener(that.$('btn_fanhui'), function () {
                if (gameData.uid != gameData.ownerUid) {
                    showMessageBox('确定要退出房间吗?', function () {
                        network.send(3003, {room_id: gameData.roomId});
                    });
                }
            });

            TouchUtil.setOnclickListener(that.$('btn_bg.btn_jiesan'), function () {
                if (that.getRoomState() == that.roomStateType.ROOM_STATE_CREATED) {
                    if (window.inReview)
                        network.send(3003, {room_id: gameData.roomId});
                    else
                        showMessageBox('解散房间不扣房卡，是否确定解散?', function () {
                            network.send(3003, {room_id: gameData.roomId});
                        });
                    return;
                }

                showMessageBox('确定要申请解散房间吗?', function () {
                    network.send(3009, {room_id: gameData.roomId, is_accept: 1});
                });
            });

            TouchUtil.setOnclickListener(that.$('btn_jiesan'), function () {
                if (window.inReview)
                    network.send(3003, {room_id: gameData.roomId});
                else
                    showMessageBox('解散房间不扣房卡，是否确定解散？', function () {
                        network.send(3003, {room_id: gameData.roomId});
                    });
            });

            TouchUtil.setOnclickListener(that.$('info0'), function () {
                that.showPlayerInfoPanel(0);
            });
            TouchUtil.setOnclickListener(that.$('info1'), function () {
                that.showPlayerInfoPanel(1);
            });
            TouchUtil.setOnclickListener(that.$('info2'), function () {
                that.showPlayerInfoPanel(2);
            });
            TouchUtil.setOnclickListener(that.$('info3'), function () {
                that.showPlayerInfoPanel(3);
            });

            TouchUtil.setOnclickListener(that.$('info0.ti'), function () {
                that.tiAlert(that.position2uid[0]);
            });
            TouchUtil.setOnclickListener(that.$('info1.ti'), function () {
                that.tiAlert(that.position2uid[1]);
            });
            TouchUtil.setOnclickListener(that.$('info2.ti'), function () {
            });
            TouchUtil.setOnclickListener(that.$('info3.ti'), function () {
                that.tiAlert(that.position2uid[3]);
            });

            this.addListener(3002, function (data) {
                gameData.last3002 = data;
                gameData.playerNum = data['max_player_cnt'];
                if (that.isReplay) {
                    gameData.mapId = data['map_id'];
                    gameData.wanfaDesp = data['desp'];
                }
                if (that.getRoomState() == that.roomStateType.ROOM_STATE_CREATED) {
                    gameData.ownerUid = data['owner'];
                    gameData.players = data['players'];
                    that.onPlayerEnterExit();
                }
                gameData.daikaiPlayer = data['daikai_player'];
                eventManager.dispatchEvent(EventKey.ClubRoomPlayerStateRefresh);
            });
            this.addListener(3003, function (data) {
                var uid = data['uid'];
                if (uid == gameData.uid) {
                    showBoard('HallBoard');
                    if (data['is_kick']) {
                        setTimeout(
                            function () {
                                showAlert("您被【" + that.uid2playerInfo[gameData.ownerUid].nickname + "】踢出房间");
                            }, 100
                        );
                    }
                    return;
                }
                if (data['is_kick']) {
                    if (gameData.uid != gameData.ownerUid) {
                        setTimeout(
                            function () {
                                showAlert("【" + that.uid2playerInfo[uid].nickname + "】被【" + that.uid2playerInfo[gameData.ownerUid].nickname + "】踢出房间");
                            }, 100
                        );
                    }
                }
                if (that.getRoomState() == that.roomStateType.ROOM_STATE_ONGOING)
                    return;
                if (data['del_room']) {
                    var owner = that.uid2playerInfo[gameData.ownerUid];
                    if (owner) {
                        showAlert('房主' + owner.nickname + '已解散房间', function () {
                            showBoard('HallBoard');
                        });
                    } else {
                        showAlert('代开房主已解散房间', function () {
                            showBoard('HallBoard');
                        });
                    }
                }
                else {
                    var uid = data['uid'];
                    _.remove(gameData.players, function (player) {
                        return player.uid == uid;
                    });
                    that.onPlayerEnterExit();
                }
                eventManager.dispatchEvent(EventKey.ClubRoomPlayerStateRefresh);
            });
            this.addListener(3004, function (data) {
                if (!data)
                    return;
                var uid = data['uid'];
                that.setReady(uid);
            });
            this.addListener(3013, function (data) {
                gameData.numOfCards = data['numof_cards'];
            });
            this.addListener(3005, function (data) {
            });
            this.addListener(3009, function (data, errorCode) {
                if (errorCode == -1) {
                    showAlert("长时间未开始,房间自动解散");
                    return
                }
                if (data["arr"] == null || data["arr"] == undefined || data["arr"] == '' || (data["arr"] && data["arr"].length == 0)) {
                    return;
                }
                var that = this;
                var arr = data['arr'];
                var leftSeconds = data['left_sec'];
                leftSeconds = (leftSeconds < 0 ? 0 : leftSeconds);
                var byUserId = data['arr'][0].uid;
                if (that.isJiesan)
                    return;
                that.isJiesan = data['is_jiesan'];

                if (!that.RoomQuitWindow) {
                    that.RoomQuitWindow = showWindow('RoomQuitWindow', leftSeconds, arr, byUserId, data);
                } else {
                    that.RoomQuitWindow.setData(leftSeconds, arr, byUserId, data);
                }
                that.RoomQuitWindow.setVisible(true);
            });
            this.addListener(3200, function () {
            });
            this.addListener(4000, function (data) {
                var uid = data['uid'];
                that.throwTurn(that.uid2position[uid]);
            });
            this.addListener(4001, function (data) {
                var uid = data['uid'];
                var paiId = data['pai_id'];
                var left = data['left'];
                var paiArr = data['pai_arr'];
                var liangPaiArr = data['liang_pai_arr'];
                that.leftPaiCnt = left;
                that.$('timer2.Text_2').setString(left);
                that.mopai(that.uid2position[uid], paiId, paiArr, liangPaiArr);
            });
            this.addListener(4002, function (data) {
                var uid = data['uid'];
                var idx = data['idx'];
                var paiId = data['pai_id'];
                var paiArr = (data['pai_arr'] || []);
                var liangPaiArr = (data['liang_pai_arr'] || []);
                var paiCnt = (data['pai_cnt'] || 0);
                var left = (data['left'] || 0);
                var row = that.uid2position[uid];
                if (gameData.mapId == app.map_id.CHANGSHA)
                    that.$('timer2.Text_2').setString(left);
                for (var i = 0; i < paiCnt; i++)
                    paiArr.push(0);
                //that.chuPai(row, idx, paiId, paiArr, liangPaiArr);

                var isAutoMsg = data['isAutoMsg'];
                //修改出牌逻辑，点击直接出牌，等消息回来刷新手牌
                if (row != 2 || that.isReplay || isAutoMsg) {
                    that.chuPai(row, idx, paiId, paiArr, liangPaiArr);
                } else {
                    if (!Equals(paiArr.sort(compareTwoNumbers), that.getPaiArr().sort(compareTwoNumbers))) {
                        that.setPaiArrOfRow(row, paiArr, (row != 2), (row != 2), []);
                        that.checkPaiAmount();
                    }
                    that.upPai(row, -1);
                    that.recalcPos(row);
                    that.resetPaiState();
                    that.xiangTongPaiBianHui(-1);
                    that.gangChiXiangTongPai(-1);
                }
                that.hideTishiTip();
            });
            this.addListener(4003, function (data) {
                var uid = data['uid'];
                var fromUid = data['from_uid'];
                var paiId = data['pai_id'];
                var op = data['op'];
                var chi = op[0];
                var peng = op[1];
                var gang = op[2];
                var hu = op[3];
                if (chi) that.chiPengGangHu(that.opType.OP_CHI, that.uid2position[uid], paiId, that.uid2position[fromUid], data);
                if (peng) that.chiPengGangHu(that.opType.OP_PENG, that.uid2position[uid], paiId, that.uid2position[fromUid], data);
                if (gang) that.chiPengGangHu(that.opType.OP_GANG, that.uid2position[uid], paiId, that.uid2position[fromUid], data);
                if (hu) that.chiPengGangHu(that.opType.OP_HU, that.uid2position[uid], paiId, that.uid2position[fromUid], data);
                if (!chi && !peng && !gang && !hu)
                    that.chiPengGangHu(that.opType.OP_PASS, that.uid2position[uid], paiId, that.uid2position[fromUid], data);
            });
            this.addListener(4004, function (data) {
                that.chiPengGangHuCode = 4004;
                var uid = data['uid'];
                var paiId = data['pai_id'];
                var op = data['op'];
                var row = that.uid2position[uid];
                that.showChiPengGangHu(row, paiId, op[0], op[1], op[2], op[3], op[4], data);
            });
            this.addListener(4005, function (data) {
                var uid = data['uid'];
                var op = data['op'];
                var row = that.uid2position[uid];
                that.showTingLiang(row, op[0], op[1]);
            });
            this.addListener(40044, function (data) {
                var arr = data['arr'];
                for (var i = 0; i < arr.length; i++) {
                    var uid = arr[i]['data']['uid'];
                    var paiId = arr[i]['data']['pai_id'];
                    var op = arr[i]['data']['op'];
                    var row = that.uid2position[uid];
                    that.showChiPengGangHu(row, paiId, op[0], op[1], op[2], op[3], op[4], data);
                }
            });
            this.addListener(4008, function (data) {
                that.setRoomState(that.roomStateType.ROOM_STATE_ENDED);
                that.jiesuan(data);
            });
            this.addListener(4009, function (data) {
                that.zongJiesuan(data);
            });
            this.addListener(4010, function (data) {
                if (!cc.sys.isObjectValid(that)) {
                    return;
                }
                var msg = data.msg;
                that.showToast(decodeURIComponent(msg));
            });
            this.addListener(4011, function (data) {
                showWindow('Ma_ZhaNiaoWindow', data);
                network.stop();
            });
            this.addListener(4012, function (data) {
                if (!that) {
                    return;
                }
                showWindow('Ma_ZhaNiaoWindow', data, 1.5);
            });
            this.addListener(4013, function (data) {
                that.showTip("第一步, 请选择一张要打出的牌");
                that.setPaiArrOfRow(2, data['pai_arr'], false, false, data['liang_pai_arr']);
                that.liangStep = 1;
            });
            this.addListener(4014, function (data) {
                var paiArr = data['pai_arr'];
                var paiArrBak = _.clone(data['pai_arr']);
                var gangPaiArr = data['gang_pai_arr'];
                if (!gangPaiArr) {

                }
                else {
                    that.showTip("请选择不想显示的杠牌");
                    that.$('btn_xuanzewancheng').setVisible(true);
                    TouchUtil.setOnclickListener(that.$('btn_xuanzewancheng'), function () {
                        that.selectHideGangCb.call(that);
                    });
                    for (var i = 0; i < gangPaiArr.length; i++) {
                        while (true) {
                            var j = paiArrBak.indexOf(gangPaiArr[i]);
                            if (j < 0)
                                break;
                            paiArrBak.splice(j, 1);
                        }
                    }
                    that.hideGangArr = gangPaiArr;
                    that.hidedGangArr = [];

                    if (gangPaiArr.length == 0)
                        that.selectHideGangCb();
                    else {
                        that.hideGangStep = 1;
                        that.setPaiArrOfRow(2, paiArr, false, false, gangPaiArr, true);
                    }
                }
                if (gameData.huTipData) {
                    that.showTishiTip(gameData.huTipData);
                    // console.log("111");
                }
            });
            this.addListener(4015, function (data) {
                that.hideGangChupaiArr = data['ting_pai_arr'];
                that.hideGangStep = 2;
                that.showTip("请出一张牌");
                var paiArr = that.getPaiArr();
                that.setPaiArrOfRow(2, paiArr, false, false, that.hideGangChupaiArr);
                if (that.$('btn_xuanzewancheng')) {
                    that.$('btn_xuanzewancheng').setVisible(false);
                }
                if (gameData.huTipData) {
                    that.showTishiTip(gameData.huTipData);
                }
            });
            this.addListener(4016, function (data) {
                if (gameData.mapId == app.map_id.YIYANG_SUOGANGZI) {
                    var uid = data['uid'];
                    var row = that.uid2position[uid];
                    setTimeout(function () {
                        that.playChiPengGangHuAnim(row, that.opType.OP_TING);
                        if (that.$('info' + row + '.liang'))
                            that.$('info' + row + '.liang').setVisible(true);
                        playEffect('vting', that.position2sex[row]);
                    }, 100)
                }
            });
            this.addListener(4020, function (data) {
                var uid = data['uid'];
                var isOffline = data['is_offline'];
                that.playerOnloneStatusChange(that.uid2position[uid], isOffline);
            });
            this.addListener(4200, function (data) {
                eventManager.dispatchEvent(EventKey.ClubRoomGameStart);
                var paiArr = data['paiArr'];
                var zhuangUid = data['zhuang_uid'];

                gameData.zhuangUid = zhuangUid;
                gameData.leftRound = data['left_round'];

                that.initExtraMapData(data);

                that.setRoomState(that.roomStateType.ROOM_STATE_ONGOING);
                that.clearTable4StartGame(true);
                that.fapai(paiArr);
                that.setZhuang(that.uid2position[zhuangUid]);

                that.forRows(function (i) {
                    var spBs = that.$('info' + i + '.sp_piao');
                    if (spBs)
                        spBs.setVisible(false);
                });


                var isSelectPiaoFinished = _.isUndefined(data['spf']) ? true : data['spf'];
                if (!isSelectPiaoFinished) {
                    that.forRows(function (i) {
                        for (var j = 0; j < 14; j++)
                            that.getPai(i, j).setVisible(false);
                    });
                }

                if (that.afterGameStart)
                    that.afterGameStart();
                that.allChiPengGangCache = {};
                that.allChiPengGangCache = null;
            });
            this.addListener(4030, function (data, errCode) {
                if (errCode == -1) {
                    that.showTip('您选择要亮的或要出的牌不正确,请重新选择');
                    that.$('btn_queding').setVisible(true);
                }
                else {
                    var uid = data['uid'];
                    that.hideTip();
                    var paiArr = data['pai_arr'];
                    var liangPaiArr = data['liang_pai_arr'] || [];

                    var row = that.uid2position[uid];
                    if (row == 2) {
                        that.afterLianging = true;
                        that.upPai(2, -1);
                    }
                    else {
                        for (var i = 0; i < paiArr.length; i++)
                            paiArr[i] = 0;
                    }

                    for (var i = 0; i < liangPaiArr.length; i++)
                        that.disabledChuPaiIdMap[liangPaiArr[i]] = true;

                    that.setPaiArrOfRow(row, paiArr, (row != 2), (row != 2), liangPaiArr);

                    if (row == 2) {
                        that.hasChupai = true;
                        that.hideTip();
                    }
                }
            });
            this.addListener(4031, function (data, errCode) {
                if (errCode == -1) {
                    that.showTip('您选择要出的牌不正确,请重新选择');
                }
                else {
                    var uid = data['uid'];
                    that.hideTip();
                    var paiArr = data['pai_arr'];
                    var hidedGangPaiArr = data['hided_gang_arr'] || [];

                    var row = that.uid2position[uid];
                    if (row == 2) {
                        that.afterLianging = true;
                        that.upPai(2, -1);
                    }
                    else {
                        for (var j = 0; j < hidedGangPaiArr.length; j++) {
                            for (var i = 0; i < 4; i++) {
                                that.getGPai(row, i, 0);
                                var g = that.$('row' + row + '.g' + i);
                                if (g.isVisible() == false) {
                                    that.setGHide(row, i);
                                    g.setVisible(true);
                                    that.recalcPos(row);
                                    break;
                                }
                            }
                        }
                    }
                    if (row == 2) {
                        that.hasChupai = true;
                        that.hideTip();
                    }
                    setTimeout(function () {
                        if (that.$('info' + row + '.liang'))
                            that.$('info' + row + '.liang').setVisible(true);
                        that.playChiPengGangHuAnim(row, that.opType.OP_LIANG);
                        playEffect('vting', that.position2sex[row]);
                    }, 100);
                }
            });
            this.addListener(4041, function (data, errCode) {
            });
            this.addListener(4050, function (data) {
                var arr = data['arr'];
                var haidiUid = data['haidi_uid'] || 0;
                var paiId = data['pai_id'] || 0;
                var allNo = true;
                for (var i = 0; i < arr.length; i++) {
                    if (arr[i].val >= 0) {
                        allNo = false;
                    }
                }
                var haiDiPaiWindow = window.curScene.getChildByName('Ma_HaiDiPaiWindow');
                if (haidiUid) {
                    if (haiDiPaiWindow) {
                        haiDiPaiWindow.removeFromParent(true);
                    }
                    if(gameData.playerMap[haidiUid]){
                        showAlert("玩家【" + gameData.playerMap[haidiUid].nickname + "】获得海底牌: " + that.PAINAMES[paiId]);
                    }
                }
                else if (allNo) {
                    if (haiDiPaiWindow) {
                        haiDiPaiWindow.removeFromParent(true);
                    }
                    showAlert('没有玩家要海底牌');
                }
                else {
                    if (!haiDiPaiWindow) {
                        showWindow('Ma_HaiDiPaiWindow', arr);
                    } else {
                        haiDiPaiWindow.setData(arr);
                    }
                }
            });
            this.addListener(4052, function (data) {
                network.stop();
                that.chiPengGangHuCode = 4052;
                var uid = data['uid'];
                var row = that.uid2position[uid];
                if (row == 2)
                    that.afterLianging = true;

                if (that.$('info' + row + '.liang'))
                    that.$('info' + row + '.liang').setVisible(true);
                if (row == 2) {
                    that.setPaiArrOfRow(2, that.getPaiArr(), false, false, []);
                    that.getPai(2, 13).setVisible(false);
                }
                var isReconnect = data['is_reconnect'] || false;
                var paiID = data['pai'];
                var paiIDA = data['pai_a'];
                var paiIDB = data['pai_b'];
                var paiStr = that.PAINAMES[paiIDA] + (paiIDB ? "," + that.PAINAMES[paiIDB] : "");

                that.showTip("开杠: " + paiStr);

                that.hideChiPengGangHu();

                var throwDiceCb = function () {
                    network.start();
                    var content = "玩家【" + ellipsisStr(_.trim(gameData.playerMap[uid].nickname), 6) + "】开杠" + that.PAINAMES[paiID] + ", 补牌: " + paiStr + "\n请选择你可以进行的操作";

                    var qgh = data['qgh'];
                    var opA = data['op_a'];
                    var opB = data['op_b'];

                    if (opA[0] + opA[1] + opA[2] + opA[3] <= 0 &&
                        opB[0] + opB[1] + opB[2] + opB[3] <= 0 && !qgh)
                        return;
                    that._Ma_KaiGangWindow = showWindow('Ma_KaiGangWindow', data, content, that);
                };

                if (isReconnect) {
                    network.start();
                    throwDiceCb();
                }
                else
                    that.throwDice("开杠摇骰子", data['dice'], paiIDA, paiIDB, throwDiceCb);
                playEffect('vsaizi');
            });
            this.addListener(4053, function (data) {
                that.showTip("请等待他人选择是否小胡");
                that.disableChupai = true;
                that.selectingXiaohu = true;
            });
            this.addListener(4054, function (data) {
                that.hideTip();
                that.disableChupai = false;
                that.selectingXiaohu = false;
            });
            this.addListener(4055, function (data) {
                that.hideTip();
                that.disableChupai = false;
                that.selectingXiaohu = false;

                var uid = data['uid'];
                var row = that.uid2position[uid];
                if (row != 2) {
                    var paiArr = data['pai_arr'];
                    var paiCnt = data['pai_cnt'];
                    var n = paiCnt - paiArr.length;
                    for (var i = 0; i < n; i++)
                        paiArr.push(0);
                    that.setPaiArrOfRow(row, paiArr, true, false);
                }

                that.playChiPengGangHuAnim(row, that.opType.OP_HU, false);
                if (gameData.speakCSH) {
                    var alchupai = false;
                    for (var i = 0; i < 4; i++) {
                        if (that.$('row' + i + '.c0.b0').isVisible()) {
                            alchupai = true;
                            break;
                        }
                    }
                    if (alchupai) {
                        playEffect('vhu_fqs', that.position2sex[row]);
                    } else {
                        playEffect('vhu_qs', that.position2sex[row]);
                    }
                } else {
                    playEffect('vhu', that.position2sex[row]);
                }

                var hu_type_arr = data['hu_type_arr'];
                if (hu_type_arr && hu_type_arr.length > 0) {
                    that.HuTypeAnimation(row, hu_type_arr.slice());
                }
            });
            this.addListener(4058, function (data) {
                showWindow('Ma_KaiGangReplayWindow', data);
            });

            this.addListener(4062, function (data) {
                that.showTishiTip(data);
            });

            this.addListener(4034, function (data, errCode) {
                that.showSelectPiao(data['sel_map']);
                var isAllSelected = true;
                for (var uid in data['sel_map'])
                    if (data['sel_map'].hasOwnProperty(uid) && uid && data['sel_map'][uid] < 0) {
                        isAllSelected = false;
                        break;
                    }
                if (!that.isReplay && !isAllSelected) {
                    that.forRows(function (i) {
                        for (var j = 0; j < 14; j++)
                            that.getPai(i, j).setVisible(false);
                    });
                }
            });
            this.addListener(4035, function (data, errCode) {
                that.hideSelectedPiao();
                that.setPaiArrOfRow(2, data['paiArr']);
                that.forRows(function (i) {
                    for (var j = 0; j < 13; j++) {
                        var pai = that.getPai(i, j);
                        pai.setOpacity(255);
                        pai.setVisible(true);
                        pai.runAction(cc.fadeIn(0.5));
                    }
                });
            });


            this._HuTipUnit = new Ma_HuTipUnit(this);
            this._HuTipUnit.setPosition(cc.p(780, 360));
            this.addChild(this._HuTipUnit);
            this._HuTipUnit.setVisible(false);


            network.start();

            that.isCCSLoadFinished = true;

            playMusic();
        },
        /**
         * 重制牌状态
         */
        resetPaiState: function () {
            var self = this;
            for (var i = 0; i < 14; i++) {
                var pai = self.getPai(2, i);
                pai.isUp = false;
                pai.isDowning = false;
                pai.isUpping = false;
                self.checkPaiPos(2);
            }
        },
        hideSelectedPiao: function () {
            var that = this;
            for (var i = 0; i < 4; i++) {
                var sp = that.$('info_n' + i + '.piao');
                sp && sp.setVisible(false);
            }
            that.$('piao_bar').setVisible(false);
        },
        showSelectPiao: function (selectPiaoMap) {
            var that = this;
            var isAllSelected = true;
            for (var uid in selectPiaoMap)
                if (selectPiaoMap.hasOwnProperty(uid) && uid && selectPiaoMap[uid] < 0) {
                    isAllSelected = false;
                    break;
                }
            if (isAllSelected) {
                for (var uid in selectPiaoMap)
                    if (selectPiaoMap.hasOwnProperty(uid)) {
                        var row = that.uid2position[uid];
                        var sp = that.$('info_n' + row + '.piao');
                        sp && sp.setVisible(false);

                        var spBs = that.$('info' + row + '.sp_piao');
                        if (spBs) {
                            spBs.setVisible(true);
                            if (selectPiaoMap[uid] == 0) {
                                spBs.setString('不飘');
                            } else {
                                spBs.setString('飘' + selectPiaoMap[uid] + '分');
                            }
                        }
                        that.$('info' + row + '.sp_piaostate0').setVisible(false);
                        that.$('info' + row + '.sp_piaostate1').setVisible(false);
                    }
            }
            else {
                for (var uid in selectPiaoMap)
                    if (selectPiaoMap.hasOwnProperty(uid)) {
                        var row = that.uid2position[uid];
                        var lbBs = that.$('info' + row + '.lb_bs');
                        lbBs && lbBs.setVisible(false);
                    }
                if (selectPiaoMap[gameData.uid] < 0) {
                    that.$('piao_bar').setVisible(true);
                    var piao0 = that.$('piao_bar.piao0');
                    var isShowPiao0 = true;//gameData.triggers && gameData.triggers[9];
                    isShowPiao0 && TouchUtil.setOnclickListener(that.$('piao_bar.piao0'), function () {
                        network.send(4033, {room_id: gameData.roomId, piao: 0});
                    });
                    if (!isShowPiao0 && piao0.isVisible()) {
                        var p1 = that.$('piao_bar.piao1');
                        var p2 = that.$('piao_bar.piao2');
                        p1.setPositionX(p1.getPositionX() - 150);
                        p2.setPositionX(p2.getPositionX() - 150);
                    }
                    piao0.setVisible(isShowPiao0);
                    TouchUtil.setOnclickListener(that.$('piao_bar.piao1'), function () {
                        network.send(4033, {room_id: gameData.roomId, piao: 1});
                    });
                    TouchUtil.setOnclickListener(that.$('piao_bar.piao2'), function () {
                        network.send(4033, {room_id: gameData.roomId, piao: 2});
                    });
                    TouchUtil.setOnclickListener(that.$('piao_bar.piao3'), function () {
                        showMessageBox("确定要 飘3分 吗?", function () {
                            network.send(4033, {room_id: gameData.roomId, piao: 3});
                        }, function () {
                        }, false, true, true, true);
                    });
                }
                for (var uid in selectPiaoMap) {
                    if (!selectPiaoMap.hasOwnProperty(uid))
                        continue;

                    var row = that.uid2position[uid];
                    var piao = selectPiaoMap[uid];
                    if (row == 2 && piao >= 0)
                        that.$('piao_bar').setVisible(false);
                    if (row == 2 && piao < 0)
                        continue;
                    var sp_piao = that.$('info' + row + '.sp_piaostate0')
                    if (sp_piao) {

                    }
                    if (piao < 0) {
                        that.$('info' + row + '.sp_piaostate0').setVisible(true);
                        that.$('info' + row + '.sp_piaostate1').setVisible(false);
                    } else {
                        that.$('info' + row + '.sp_piaostate0').setVisible(false);
                        that.$('info' + row + '.sp_piaostate1').setVisible(true);
                    }
                }
            }
        },
        HuTypeAnimation: function (row, arr) {
            var that = this;
            if (arr.length > 0) {
                var huType = arr.shift();
                var typeSprite = new cc.Sprite(majiang_hn.res['huType_' + huType]);
                that.$('info_n' + row).addChild(typeSprite);
                typeSprite.runAction(
                    cc.sequence(
                        cc.moveBy(1.2, cc.p(0, 150)).easing(cc.easeOut(3.0)),
                        cc.callFunc(function () {
                            typeSprite.removeFromParent(true);
                            that.HuTypeAnimation(row, arr);
                        })
                    )
                );
            }
        },

        getUserHeaderData: function () {
            var that = this;
            var data = {};
            var players = gameData.players;
            var scale = cc.view.getFrameSize().width / cc.director.getWinSize().width;
            var theight = cc.view.getFrameSize().height / scale;
            var boardHeight = (theight - cc.director.getWinSize().height) / 2;
            for (var i = 0; i < players.length; i++) {
                var player = players[i];
                var pos = 0;
                var header = that.$('info' + pos + '.head');
                var headerPos = header.convertToWorldSpace(cc.p(0, 0));
                var width = header.getBoundingBox().width;
                var height = header.getBoundingBox().height;
                var x = headerPos.x;
                var y = headerPos.y + height - boardHeight;
                data[player.uid] = {
                    x: x,
                    y: y,
                    width: width,
                    height: height
                };
            }
            return JSON.stringify(data);
        },

        createVideoView: function () {
            // if (!bShowVideo) {
            //     bShowVideo = true;
            //     PermissionUtils.hasPermission("android.permission.CAMERA");
            //     AgoraUtil.initVideoView(this.getUserHeaderData());
            //     setTimeout(function () {
            //         AgoraUtil.openVideo(gameData.roomId.toString(), gameData.uid.toString());
            //     }, 1000);
            // }
        },

        hideWanfaLayer: function () {
            var that = this;
            if (this.wanfaLayer != null) {
                this.wanfaLayer.setVisible(false);
            }
        },
        hideTishiTip: function () {
            var that = this;
            for (var i = 0; i < 14; i++) {
                (function (i) {
                    var cardSprite = that.getPai(2, i);
                    var hucardSprite = cardSprite.getChildByName('hucardSprite');
                    if (hucardSprite)
                        hucardSprite.setVisible(false);
                })(i);
            }
        },
        showTishiTip: function (data) {
            var that = this;
            if (data == null || that.hasChupai) return;

            //本地数据
            this.hupaiTipData = data.tishi;
            var myPaiArr = this.getPaiArr();
            var hupai_tip = this._HuTipUnit;
            hupai_tip.setVisible(false);
            var huCurCard = 0;
            if(data.lastChuPai){
                huCurCard = data.lastChuPai;
            }
            if(huCurCard > 0 && this.hupaiTipData && this.hupaiTipData[huCurCard])  this._HuTipUnit.initHuPaiTishiLayer(this.hupaiTipData[huCurCard]);

            if (!this.isMyTurn()) {
                return;
            }
            gameData.huTipData = data;
            //胡牌提示
            for (var i = 0; i < 14; i++) {
                (function (i) {
                    var cardSprite = that.getPai(2, i);
                    var paiId = cardSprite.paiId;
                    var hucards = null;
                    for (var cards in data.tishi) {
                        if (parseInt(cards) == parseInt(paiId)) {
                            hucards = data.tishi[cards];
                            break;
                        }
                    }
                    var hucardSprite;
                    if (cardSprite.getChildByName('hucardSprite')) {
                        hucardSprite = cardSprite.getChildByName('hucardSprite');
                        hucardSprite.setPosition(cardSprite.getContentSize().width / 2 - 24.5, cardSprite.getContentSize().height - 33);
                    } else {
                        hucardSprite = new cc.Sprite(majiang_hn.res.PaiUnit_hupaitip_jiao);
                        hucardSprite.setPosition(cardSprite.getContentSize().width / 2 - 24.5, cardSprite.getContentSize().height - 33);
                        hucardSprite.setName('hucardSprite');
                        cardSprite.addChild(hucardSprite);
                    }
                    var duration = 2;
                    hucardSprite.setVisible(!!hucards);
                    cardSprite.hucards = hucards;
                })(i);
            }
        },
        tiAlert: function (destUid) {
            var that = this;
            showMessageBox("是否踢出【" + that.uid2playerInfo[destUid].nickname + "】该玩家？", function () {
                network.send(3010, {room_id: gameData.roomId, dest_uid: destUid});
            }, function () {
            });
        },
        onExit: function () {
            var that = this;
            if (this.list2103) cc.eventManager.removeListener(this.list2103);
            if (this.list1) cc.eventManager.removeListener(this.list1);
            if (this.list2) cc.eventManager.removeListener(this.list2);
            network.removeListener(EventKey.ChangeBgm);
            network.removeListener(EventKey.ChangeTable);
            network.removeListenersForTarget(this);
            cc.Layer.prototype.onExit.call(this);
        },
        onPlayerEnterExit: function () {
            eventManager.dispatchEvent(EventKey.ClubPlayerEnterExit, gameData.players);
            var that = this;
            that.uid2position = {};
            that.uid2playerInfo = {};
            that.position2uid = {};
            that.position2sex = {};
            that.position2playerArrIdx = {};
            var players = gameData.players;
            for (var i = 0; i < players.length; i++) {
                var player = players[0];
                if (player.uid != gameData.uid) {
                    players.splice(0, 1);
                    players.push(player);
                }
                else
                    break;
            }
            that.$('timer').delta = i;
            for (var i = 0, j = 2; i < players.length; i++, j++) {
                var player = players[i];
                var k = {
                    4: {'0': 0, '1': 3, '2': 2, '3': 1},
                    3: {'0': 1, '1': 3, '2': 2},
                    2: {'0': 2, '1': 0}
                }[that.playerNums][j % that.playerNums];
                that.$('info' + k).setVisible(true);
                that.$('info' + k + '.lb_nickname').setString(ellipsisStr(player['nickname'], (k == 0 || k == 2 ? 7 : 5)));
                that.$('info' + k + '.lb_score').setString(that.roomState == that.roomStateType.ROOM_STATE_CREATED ? 1000 : player['score'] + 1000);
                if (that.roomState == that.roomStateType.ROOM_STATE_CREATED) {
                    that.$('info' + k + '.ok').setVisible(!!player['ready']);
                    if (gameData.uid == player.uid) {
                        that.$('btn_zhunbei').setVisible(!player['ready']);
                    }
                }
                if (k != 2 && gameData.uid == gameData.ownerUid && that.getRoomState() == that.roomStateType.ROOM_STATE_CREATED) {
                    that.$('info' + k + '.ti').setVisible(true);
                }
                loadImageToSprite(player['headimgurl'], that.$('info' + k + '.head'));
                that.uid2position[player.uid] = k;
                that.uid2playerInfo[player.uid] = player;
                that.position2uid[k] = player.uid;
                that.position2sex[k] = player.sex;
                that.position2playerArrIdx[k] = i;
            }
            for (; i < that.playerNums; i++, j++) {
                var k = {
                    4: {'0': 0, '1': 3, '2': 2, '3': 1},
                    3: {'0': 1, '1': 3, '2': 2},
                    2: {'0': 2, '1': 0}
                }[that.playerNums][j % that.playerNums];
                that.$('info' + k).setVisible(false);
            }

            if (that.playerNums == 3) {
                that.$('info0').setVisible(false);
                that.$('row1').y = 242; // todo 这里暂时写死
                that.$('row3').y = 135; // todo 这里暂时写死
            }

            if (that.playerNums == 2) {
                that.$('info1').setVisible(false);
                that.$('info3').setVisible(false);
            }

            if (gameData.uid == gameData.ownerUid) {
                if (players.length < that.playerNums) {
                    that.$('btn_yxks').setVisible(false);
                } else if (that.getRoomState() == that.roomStateType.ROOM_STATE_CREATED) {
                    that.$('btn_yxks').setVisible(gameData.AutoReady);
                }
            }else{
                that.$('btn_yxks').setVisible(false);
            }

            if (players.length < that.playerNums) {
                that.$('btn_invite').setVisible(gameData.loginType != 'yk' && !that.isReplay);
                that.$('btn_copy').setVisible(gameData.loginType != 'yk' && !that.isReplay);
            } else if (that.getRoomState() == that.roomStateType.ROOM_STATE_CREATED) {
                that.$('btn_invite').setVisible(false);
                that.$('btn_copy').setVisible(false);
            }
        },
        calcPosConf: function () {
            var that = this;
            for (var row = 0; row < 4; row++) {
                var a0 = that.$('row' + row + '.a0');
                that.posConf.paiA0PosBak[row] = a0.getPosition();
                that.posConf.paiA0ScaleBak[row] = [a0.getScaleX(), a0.getScaleY()];
                that.posConf.headPosBak[row] = that.$('info' + row).getPosition();

                if (row == 0 || row == 2) {
                    var a0 = that.$('row' + row + '.a0');
                    var a1 = that.$('row' + row + '.a1');
                    that.posConf.paiADistance.push(a1.getPositionX() - a0.getPositionX());
                    var b0 = that.$('row' + row + '.c0.b0');
                    var b1 = that.$('row' + row + '.c0.b1');
                    that.posConf.paiUsedDistance.push(b1.getPositionX() - b0.getPositionX());

                    that.posConf.downPaiPositionY = a0.getPositionY();
                    that.posConf.upPaiPositionY = a0.getPositionY() + that.UPPAI_Y;
                }
                else {
                    var a0 = that.$('row' + row + '.a0');
                    var a1 = that.$('row' + row + '.a1');
                    that.posConf.paiADistance.push(a1.getPositionY() - a0.getPositionY());
                    var b0 = that.$('row' + row + '.c0.b0');
                    var b1 = that.$('row' + row + '.c0.b1');
                    that.posConf.paiUsedDistance.push(b1.getPositionY() - b0.getPositionY());
                }

                var b0 = that.$('row' + row + '.g0.b0');
                var b2 = that.$('row' + row + '.g0.b2');

                if (row == 0) that.posConf.groupWidth[0] = b0.getPositionX() + b0.getContentSize().width / 2 - (b2.getPositionX() - b2.getContentSize().width / 2);
                if (row == 2) that.posConf.groupWidth[2] = b2.getPositionX() + b2.getContentSize().width / 2 - (b0.getPositionX() - b0.getContentSize().width / 2);
                if (row == 1) that.posConf.groupHeight[1] = b2.getPositionY() + b2.getContentSize().height / 2 - (b0.getPositionY() - b0.getContentSize().height / 2);
                if (row == 3) that.posConf.groupHeight[3] = b0.getPositionY() + b0.getContentSize().height / 2 - (b2.getPositionY() - b2.getContentSize().height / 2);
            }
        },
        forRows: function (cb) {
            var that = this;
            if (that.playerNums == 2) {
                cb.call(that, 0);
                cb.call(that, 2);
            } else if (that.playerNums == 3) {
                cb.call(that, 1);
                cb.call(that, 2);
                cb.call(that, 3);
            } else {
                cb.call(that, 0);
                cb.call(that, 1);
                cb.call(that, 2);
                cb.call(that, 3);
            }
        },
        setRoomData: function (data, roomDataType) {
            var that = this;
            that.isReplay = (roomDataType == ROOM_DATA_TYPE.REPLAY);
            that.isReconnect = (roomDataType == ROOM_DATA_TYPE.RECONNECT);
            that.roomData = data;
            that.uid = gameData.uid;
            that.mapId = gameData.mapId;
            that.playerNums = gameData.playerNum;
            that.options = gameData.options;
        },
        ctor: function (data, roomDataType) {
            this._super();
            var that = this;
            network.stop();
            that.setRoomData(data, roomDataType);
            loadCCSTo(majiang_hn.res.MaRoomHuNan_json, this, "Scene");
            this.changeBgm();
            if (!cc.sys.isNative)
                this.initTestFapai();
            return true;
        },

        initTestFapai: function () {
            // var that = this;
            // var test = new cc.Sprite('res/chat/chat_lan.png');
            // test.setPosition(cc.p(500, 700));
            // that.addChild(test);
            // TouchUtil.setOnclickListener(test, function () {
            //     that.addChild(new testFaPaiLayer());
            // });
        },
        initBG: function (id) {
            var that = this;
            var bg = that.$("bg");
            var tableid = id || settingData.local_table[gameData.mapId] || 0;
            bg.setTexture(majiang_hn.res["table_back" + tableid + "_jpg"]);
        },
        initLog: function () {
            var that = this;
            var logo = that.$("logo");
            var resLog = majiang_hn.res.majiang_logo_CS;
            switch (gameData.mapId) {
                case app.map_id.CHANGSHA:
                    resLog = majiang_hn.res.majiang_logo_CS;
                    break;
                case app.map_id.ZHUANZHUAN:
                    resLog = majiang_hn.res.majiang_logo_ZZ;
                    break;
                case app.map_id.HONGZHONG:
                    resLog = majiang_hn.res.majiang_logo_HZ;
                    break;
                case app.map_id.YIYANG:
                    resLog = majiang_hn.res.majiang_logo_yiyang;
                    break;
                case app.map_id.YIYANG_SUOGANGZI:
                    resLog = majiang_hn.res.majiang_logo_suogangzi;
                    break;
                case app.map_id.YUEYANG:
                    resLog = majiang_hn.res.majiang_logo_yueyang;
                    break;
                case app.map_id.SHAOYANG:
                    resLog = majiang_hn.res.majiang_logo_shaoyang;
                    break;
                case app.map_id.CHENZHOU:
                    resLog = majiang_hn.res.majiang_logo_chenzhou;
                    break;
            }
            //logo.setTexture(resLog);
        },
        /**
         * 切换背景音乐
         */
        changeBgm: function (id) {
            //背景声音
            if (settingData.jingyinopen) {
                stopMusic();
            } else if (settingData.musicvoice) {
                var setting_bgm = settingData.local_bgMusic[gameData.mapId] || 1;
                playMusic("vbg_ma" + setting_bgm);
            }
        },
        startSignal: function () {
            var that = this;
            var interval = null;
            var lastDealy = -1;
            var func = function () {
                if (!that || !cc.sys.isObjectValid(that))
                    return clearInterval(interval);
                var delay = network.getLastPingInterval();
                if (delay == lastDealy)
                    return;
                lastDealy = delay;
                if (delay < 100) that.$('signal').setTexture(majiang_hn.res.signal5);
                else if (delay < 200) that.$('signal').setTexture(majiang_hn.res.signal4);
                else if (delay < 300) that.$('signal').setTexture(majiang_hn.res.signal3);
                else if (delay < 600) that.$('signal').setTexture(majiang_hn.res.signal2);
                else that.$('signal').setTexture(majiang_hn.res.signal1);
            };
            func();
            interval = setInterval(func, 200);
        },
        startTime: function () {
            var that = this;
            var interval = null;
            var flag = true;
            var lbTime = that.$('lb_time');
            if (that.isReplay) {
                if (cc.sys.isObjectValid(lbTime)) {
                    lbTime.setString('--:--');
                }
                return;
            }
            var updTime = function () {
                //显示电池电量
                var battery = that.$('battery');
                if (cc.sys.isObjectValid(battery)) {
                    var level = DeviceUtil.getBatteryLevel();
                    if (cc.sys.isObjectValid(battery)) {
                        if (level > 75) {
                            battery.setTexture(majiang_hn.res.battery_5);
                        } else if (level > 50) {
                            battery.setTexture(majiang_hn.res.battery_4);
                        } else if (level > 25) {
                            battery.setTexture(majiang_hn.res.battery_3);
                        } else if (level > 10) {
                            battery.setTexture(majiang_hn.res.battery_2);
                        } else {
                            battery.setTexture(majiang_hn.res.battery_1);
                        }
                    }
                }
                var date = new Date();
                var minutes = (date.getMinutes() < 10 ? '0' : '') + date.getMinutes();
                var hours = (date.getHours() < 10 ? '0' : '') + date.getHours();
                if (cc.sys.isObjectValid(lbTime))
                    lbTime.setString(hours + (flag ? ':' : ' ') + minutes);
                else if (interval)
                    clearInterval(interval);
                flag = !flag;
            };
            updTime();
            interval = setInterval(updTime, 1000);
        },
        isMyTurn: function () {
            var that = this;
            return that.turnRow == 2;
        },
        getTurn: function () {
            var that = this;
            for (var i = 0; i < 4; i++) {
                var node = that.$('timer.' + i);
                if (node.isVisible())
                    return (i + that.$('timer').delta) % 4;
            }
            return -1;
        },
        throwTurnByUid: function (uid) {
            var that = this;
            this.throwTurn(that.uid2position[uid]);
        },
        throwTurn: function (row) {
            var that = this;
            that.turnRow = row;

            that.$('timer').setVisible(true);
            that.$('timer2').setVisible(true);

            var arrow = null;
            for (var j = 0; j < 4; j++) {
                if (j == row) {
                    arrow = that.$('timer.arrow' + j);
                    that.$('timer.txt' + j).setTextColor(cc.color(0, 0, 0));
                    that.$('timer.arrow' + j).setVisible(true);
                }
                else {
                    that.$('timer.txt' + j).setTextColor(cc.color(202, 202, 202));
                    that.$('timer.arrow' + j).setVisible(false);
                }
            }

            if (arrow) {
                if (arrow.getNumberOfRunningActions() == 0)
                    arrow.runAction(new cc.RepeatForever(cc.sequence(cc.fadeTo(0.5, 168), cc.fadeTo(0.5, 255))));
            }

            if (!that.afterLianging) {
                for (var i = 0; i < 14; i++) {
                    var pai = this.getPai(2, i);
                    if (row == 2) {
                        pai.isLiang = true;
                        Filter.remove(pai);
                    }
                    else {
                        pai.isLiang = false;
                        Filter.grayMask(pai);
                    }
                }
            } else {
                for (var i = 0; i < 14; i++) {
                    (function (i) {
                        var pai = that.getPai(2, i);
                        if (i == 13) {
                            pai.isLiang = true;
                            Filter.remove(pai);
                        } else {
                            pai.isLiang = false;
                            Filter.grayMask(pai);
                        }
                    })(i)
                }
            }

            if (row == 2)
                this.upPai(2, -1);
            this.hideTip();
            gameData.huTipData = null;
        },
        setPai: function (row, idx, val, isLittle, isStand, isVisible) {
            var that = this;
            var pai = this.getPai(row, idx);
            if ((gameData.mapId == app.map_id.ZHUANZHUAN || gameData.mapId == app.map_id.HONGZHONG) && gameData.playerNum > 2) {
                var lb = pai.getChildByName('lb');
                if (row == 2 && val == 32) {
                    if (!lb) {
                        lb = new cc.Sprite(majiang_hn.res.lb_lai);
                        lb.setTexture(majiang_hn.res.lb_lai);
                        lb.setName('lb');
                        pai.addChild(lb);
                        lb.setPosition(14.8, 16.5);
                    }
                    else
                        lb.setTexture(majiang_hn.res.lb_lai);
                    lb.setVisible(true);
                }
                else if (lb) {
                    lb.setVisible(false);
                }
            }

            var paiName = that.getPaiNameByRowAndId(row, val, isLittle, val > 0 ? false : (that.isReplay || that.roomState == that.roomStateType.ROOM_STATE_ENDED ? false : isStand));
            pai.paiId = val;
            that.setSpriteFrameByName(pai, paiName, 'pai');
            if (!_.isUndefined(isVisible)) {
                if (isVisible)
                    pai.setVisible(true);
                else
                    pai.setVisible(false);
            }
            return pai;
        },
        getPai: function () {
            var that = this;
            var cache = {};
            return function (row, id) {
                cache[row] = cache[row] || {};
                if (cache[row][id])
                    return cache[row][id];
                var node = that.$('row' + row + '.a' + id);
                if (!node) {
                    var a0 = that.$('row' + row + '.a0');
                    node = duplicateNode(a0, true);
                    if (node == undefined) {
                        network.disconnect();
                        return;
                    }
                    if (row == 0 || row == 2) node.setPositionX(that.posConf.paiADistance[row] * id + a0.getPositionX());
                    if (row == 1 || row == 3) node.setPositionY(that.posConf.paiADistance[row] * id + a0.getPositionY());
                    node.setName("a" + id);
                    a0.getParent().addChild(node, (row == 1 ? -id : 0));
                }
                node.idx = id;
                cache[row][id] = node;
                return node;
            }
        },
        getPaiId: function (row, id) {
            var that = this;
            return this.getPai(row, id).paiId;
        },
        setPaiFrom: function (pai, row, formId) {
            var that = this;
            if (pai && cc.sys.isObjectValid(pai) && pai.isVisible() && formId) {
                var from = that.posConf.gPaiPos[row][that.uid2position[formId]];
                if (from == undefined) {
                    from = 3;
                }
                var texture = majiang_hn.res['PaiUnit_narrow_' + from];
                if (texture) {
                    var narrow = pai.getChildByName('narrow');
                    if (narrow) {
                        narrow.setTexture(texture);
                    } else {
                        narrow = new cc.Sprite(texture);
                        pai.addChild(narrow);
                        narrow.setName('narrow');
                    }
                    narrow.setRotation(that.posConf.huFromAngle[row]);
                    narrow.setPosition(that.posConf.fromPos[row]);
                }
            }
        },
        setGChi: function (row, j, paiId, oriPaiId, fromId) {
            var that = this;
            var a = 0, b = 0, c = 0;
            if (_.isArray(paiId)) {
                a = paiId[0];
                b = paiId[1];
                c = paiId[2];
            }
            else {
                if (paiId - 1 == oriPaiId) {
                    a = paiId;
                    b = paiId - 1;
                    c = paiId + 1;
                }
                if (paiId == oriPaiId) {
                    a = paiId - 1;
                    b = paiId;
                    c = paiId + 1;
                }
                if (paiId + 1 == oriPaiId) {
                    a = paiId - 1;
                    b = paiId + 1;
                    c = paiId;
                }
            }
            this.setGPai(row, j, 0, a);
            this.setGPai(row, j, 1, b);
            this.setGPai(row, j, 2, c);
            that.$('row' + row + '.g' + j + '.b' + 3).setVisible(false);
            that.$('row' + row + '.g' + j).setVisible(true);
            this.setPaiFrom(that.$('row' + row + '.g' + j + '.b' + 0), row, fromId);
        },
        setGPai: function (row, g, idx, val) {
            var that = this;
            var pai = this.getGPai(row, g, idx);
            var paiName = that.getPaiNameByRowAndId(row, val, true);
            pai.paiId = val;
            that.setSpriteFrameByName(pai, paiName, 'pai');
        },
        setGPeng: function (row, j, paiId, fromId) {
            var that = this;
            for (var k = 0; k < 3; k++)
                this.setGPai(row, j, k, paiId);
            that.$('row' + row + '.g' + j + '.b' + 3).setVisible(false);
            that.$('row' + row + '.g' + j).setVisible(true);
            this.setPaiFrom(that.$('row' + row + '.g' + j + '.b' + 0), row, fromId);
        },
        setGHide: function (row, j) {
            var that = this;
            for (var k = 0; k < 3; k++)
                this.setGPai(row, j, k, 0);
            that.$('row' + row + '.g' + j + '.b' + 3).setVisible(false);
            that.$('row' + row + '.g' + j).setVisible(true);
        },
        setGGang: function (row, j, upPaiId, downPaiId, fromId) {
            var that = this;
            this.setGPai(row, j, 3, upPaiId);
            that.$('row' + row + '.g' + j + '.b' + 3).setVisible(true);
            for (var k = 0; k < 3; k++)
                this.setGPai(row, j, k, downPaiId);
            that.$('row' + row + '.g' + j).setVisible(true);
            this.setPaiFrom(that.$('row' + row + '.g' + j + '.b' + 0), row, fromId);
        },
        setGJiaGang: function (row, paiId, fromId) {
            var that = this;
            for (var j = 0; j < 4; j++)
                if (that.$('row' + row + '.g' + j).isVisible() &&
                    this.getGPaiId(row, j, 0) == paiId &&
                    this.getGPaiId(row, j, 0) == this.getGPaiId(row, j, 1) &&
                    this.getGPaiId(row, j, 1) == this.getGPaiId(row, j, 2)) {
                    this.setGPai(row, j, 3, paiId);
                    this.getGPai(row, j, 3).setVisible(true);
                    break;
                }
            this.setPaiFrom(that.$('row' + row + '.g' + j + '.b' + 0), row, fromId);
        },
        getGPai: function () {
            var that = this;
            var cache = {};
            return function (row, g, id) {
                cache[row] = cache[row] || {};
                cache[row][g] = cache[row][g] || {};
                if (cache[row][g][id])
                    return cache[row][g][id];
                var group0 = that.$('row' + row + '.g' + 0);
                var groupNode = that.$('row' + row + '.g' + g);
                if (!groupNode) {
                    groupNode = duplicateNode(group0);
                    if (row == 0 || row == 2) groupNode.setPositionX(group0.getPositionX() + that.posConf.groupWidth[row] * g + that.posConf.paiADistance[row] * g);
                    if (row == 1 || row == 3) groupNode.setPositionY(group0.getPositionY() + that.posConf.groupHeight[row] * g + that.posConf.paiADistance[row] * g);
                    groupNode.setName("g" + g);
                    groupNode.setVisible(false);
                    group0.getParent().addChild(groupNode);
                }
                var node = that.$('row' + row + '.g' + g + '.b' + id);
                cache[row][g][id] = node;
                this.setChiPengGangCache(row, node);
                node.idx = id;
                return node;
            }
        },
        getGPaiId: function (row, g, id) {
            var that = this;
            return that.$('row' + row + '.g' + g + '.b' + id).paiId;
        },
        checkPaiAmount: function () {
            var that = this;
            if (cc.sys.isNative)
                return;
            var amount = 0;
            var row = 2;
            for (var j = 0; j < 4; j++) {
                var g = that.$('row' + row + '.g' + j);
                if (!g || !that.$('row' + row + '.g' + j).isVisible())
                    break;
                else
                    amount += 3;
            }
            for (var j = 0; j < 14; j++)
                if (this.getPai(row, j).isVisible())
                    amount += 1;
            if (amount < 13 || amount > 14)
                alert("你的牌数量可能不对: " + amount + ", 数一下");
        },
        recalcPos: function (row) {
            var that = this;
            var g0 = that.$('row' + row + '.g' + 0);
            var g0b0pos = getPositionRelativeToParent(this.getGPai(row, 0, 0), 2);
            for (var i = 1; i < 4; i++) {
                var g = that.$('row' + row + '.g' + i);
                if (g && g.isVisible()) {
                    if (row == 0 || row == 2)
                        g.setPositionX(g0.getPositionX() + (that.posConf.groupWidth[row] * i + that.posConf.groupDistance[row] * i) * (row == 2 ? 1 : -1));
                    if (row == 1 || row == 3)
                        g.setPositionY(g0.getPositionY() + (that.posConf.groupHeight[row] * i + that.posConf.groupDistance[row] * i) * (row == 1 ? 1 : -1));
                }
                else
                    break;
            }
            var k = i;
            var m = (k > 1 || g0.isVisible() ? 1 : 0);

            var a0 = this.getPai(row, 0);
            var to = 0;
            var p = (row == 1 || row == 2 ? 1 : -1);
            if (row == 0 || row == 2) to = !m ? that.posConf.paiA0PosBak[row].x : g0b0pos.x + (that.posConf.groupWidth[row] * k + that.posConf.groupDistance[row] * k + that.posConf.groupToFirstPaiDistance[row]) * p;
            if (row == 1 || row == 3) to = !m ? that.posConf.paiA0PosBak[row].y : g0b0pos.y + (that.posConf.groupHeight[row] * k + that.posConf.groupDistance[row] * k + that.posConf.groupToFirstPaiDistance[row]) * p;
            if (row == 0 || row == 2) a0.setPositionX(to);
            if (row == 1 || row == 3) a0.setPositionY(to);
            for (var i = 1; i < 13; i++) {
                var a = this.getPai(row, i);
                if (row == 0) a.setPosition(a0.getPositionX() + i * that.posConf.paiADistance[row] + (a.paiId > 0) * i * that.posConf.paiALiangDistance[row], a0.getPositionY());
                if (row == 2) {
                    a.setPositionX(a0.getPositionX() + i * that.posConf.paiADistance[row] + (a.paiId > 0) * i * that.posConf.paiALiangDistance[row]);
                    if (!a.isUpping && !a.isDowning)
                        a.setPositionY(a.isUp ? that.posConf.upPaiPositionY : that.posConf.downPaiPositionY);
                }
                if (row == 1 || row == 3) a.setPosition(a0.getPositionX(), a0.getPositionY() + i * that.posConf.paiADistance[row] + (a.paiId > 0) * i * that.posConf.paiALiangDistance[row]);
            }

            // recalc pai 13 position
            for (var i = 12; i >= 0; i--) {
                var pai = this.getPai(row, i);
                if (pai && pai.isVisible()) {
                    var p = (row == 1 || row == 2 ? 1 : -1);
                    if (row == 0) this.getPai(row, 13).setPosition(pai.getPositionX() + that.posConf.paiADistance[row] + that.posConf.paiMopaiDistance[row] * p, a0.getPositionY());
                    if (row == 2) {
                        this.getPai(row, 13).setPositionX(pai.getPositionX() + that.posConf.paiADistance[row] + that.posConf.paiMopaiDistance[row] * p);
                        if (!pai.isUpping && !pai.isDowning)
                            a.setPositionY(pai.isUp ? that.posConf.upPaiPositionY : that.posConf.downPaiPositionY);
                    }
                    if (row == 1 || row == 3) this.getPai(row, 13).setPosition(a0.getPositionX(), pai.getPositionY() + that.posConf.paiADistance[row] + that.posConf.paiMopaiDistance[row] * p);
                    break;
                }
            }

            that.posConf.paiPos[row] = [];
            for (var i = 0; i < 14; i++) {
                that.posConf.paiPos[row].push(this.getPai(row, i).getPosition());
            }
            for (var i = 14; i < 18; i++) {
                var pai = that.$('row' + row + '.a' + i);
                if (pai)
                    pai.setVisible(false);
            }
        },
        hidePai: function (row, id) {
            var that = this;
            this.getPai(row, id).setVisible(false);
        },
        getPaiArr: function () {
            var that = this;
            var arr = [];
            for (var j = 0; j < 14; j++) {
                var pai = this.getPai(2, j);
                if (pai.paiId > 0)
                    arr.push(pai.paiId);
            }
            return arr;
        },
        addUsedPai: function () {
            var that = this;
            var cache = {};
            if (this.allCache == null) {
                this.allCache = {};
            }
            return function (row, val) {
                cache[row] = cache[row] || {};
                for (var idx = 0; idx < 50; idx++) {
                    var j = row == 1 || row == 3 ? idx + parseInt(idx / 9) : idx;
                    var pai = cache[row][j] || that.$('row' + row + '.c0.b' + j);
                    if (!pai) {
                        var k = parseInt(j / 10) * 10;
                        var b = that.$('row' + row + '.c0.b' + k);
                        if (!b) {
                            var b0 = that.$('row' + row + '.c0.b0');
                            var b10 = that.$('row' + row + '.c0.b10');
                            b = duplicateNode(b0);
                            b.setName('b' + k);
                            if (row == 0) b.setPositionY(parseInt(j / 10) * (b10.getPositionY() - b0.getPositionY()) + b0.getPositionY());
                            if (row == 1) b.setPositionX(parseInt(j / 10) * (b10.getPositionX() - b0.getPositionX()) + b0.getPositionX());
                            if (row == 2) b.setPositionY(parseInt(j / 10) * (b10.getPositionY() - b0.getPositionY()) + b0.getPositionY());
                            if (row == 3) b.setPositionX(parseInt(j / 10) * (b10.getPositionX() - b0.getPositionX()) + b0.getPositionX());
                            b0.getParent().addChild(b);
                            if (row == 2)
                                b.setLocalZOrder(k * -1);
                            pai = b;
                            pai.setVisible(false);
                        }
                        if (!pai) {
                            pai = duplicateNode(b);
                            if (row == 0 || row == 2) pai.setPositionX(that.posConf.paiUsedDistance[row] * (j - k) + b.getPositionX());
                            if (row == 1 || row == 3) pai.setPositionY(that.posConf.paiUsedDistance[row] * (j - k) + b.getPositionY());
                            pai.setName("b" + j);
                            pai.setVisible(false);
                            cc.log(row, k, j * that.posConf.paiUsedZOrder[row][k]);
                            b.getParent().addChild(pai, j * that.posConf.paiUsedZOrder[row][k]);
                            cache[row][j] = pai;
                        }
                    }

                    pai.idx = j;
                    pai.paiId = val;
                    if (!pai.isVisible()) {
                        var paiName = that.getPaiNameByRowAndId(row, val, true);
                        that.setSpriteFrameByName(pai, paiName, 'pai');
                        pai.setVisible(true);
                        if (!this.allCache[row]) {
                            this.allCache[row] = [];
                        }
                        this.allCache[row].push({idx: j, pai: val});
                        return pai;
                    }
                }
            }
        },
        removeOneTopUsedPai: function (row, paiId) {
            var that = this;
            for (var j = 60; j >= 0; j--) {
                var pai = that.$('row' + row + '.c0.b' + j);
                if (pai && pai.isVisible()) {
                    if (!_.isUndefined(paiId) && pai.paiId != paiId)
                        return;
                    pai.paiId = 0;
                    pai.setVisible(false);
                    break;
                }
            }
            this.hideArrow();
        },
        getRoomState: function () {
            var that = this;
            return that.roomState;
        },
        setRoomState: function (state) {
            eventManager.dispatchEvent(EventKey.ClubRoomStateChange, state);
            var that = this;
            that.$('btn_control_btns').setVisible(state != that.roomStateType.ROOM_STATE_CREATED && !that.isReplay);
            that.$('signal').setVisible(state != that.roomStateType.ROOM_STATE_CREATED && !that.isReplay);
            that.$('btn_chat').setVisible(state != that.roomStateType.ROOM_STATE_CREATED && !that.isReplay);
            that.$('btn_mic').setVisible(state != that.roomStateType.ROOM_STATE_CREATED && !that.isReplay);
            that.$('timer').setVisible(state == that.roomStateType.ROOM_STATE_ONGOING);
            that.$('timer2').setVisible(state == that.roomStateType.ROOM_STATE_ONGOING);
            that.$('btn_invite').setVisible(state == that.roomStateType.ROOM_STATE_CREATED);
            that.$('btn_copy').setVisible(state == that.roomStateType.ROOM_STATE_CREATED);
            that.$('btn_fanhui').setVisible(state == that.roomStateType.ROOM_STATE_CREATED && gameData.uid != gameData.ownerUid);
            that.$('btn_jiesan').setVisible(state == that.roomStateType.ROOM_STATE_CREATED && gameData.uid == gameData.ownerUid);

            if (state == that.roomStateType.ROOM_STATE_CREATED) {
                that.$('row0').setVisible(false);
                that.$('row1').setVisible(false);
                that.$('row2').setVisible(false);
                that.$('row3').setVisible(false);
                if (that.$('btn_queding')) that.$('btn_queding').setVisible(false);
                if (that.$('btn_quxiao')) that.$('btn_quxiao').setVisible(false);
                if (that.$('btn_xuanzewancheng')) that.$('btn_xuanzewancheng').setVisible(false);
                if (that.$('piao_bar')) that.$('piao_bar').setVisible(false);
                for (var i = 0; i < 4; i++) {
                    that.$('info' + i).setPosition(that.$('info_n' + i).getPosition());
                }
                this.hideArrow();
                that.disabledChuPaiIdMap = {};
                that.createVideoView();
                that.lianging = false;
                that.afterLianging = false;
            }
            if (state == that.roomStateType.ROOM_STATE_ONGOING) {
                that.$('btn_zhunbei').setVisible(false);
                that.$('btn_yxks').setVisible(false);
                if (that.$('btn_queding')) that.$('btn_queding').setVisible(false);
                if (that.$('btn_quxiao')) that.$('btn_quxiao').setVisible(false);
                if (that.$('btn_xuanzewancheng')) that.$('btn_xuanzewancheng').setVisible(false);
                that.$('row0').setVisible(true);
                that.$('row1').setVisible(true);
                that.$('row2').setVisible(true);
                that.$('row3').setVisible(true);
                that.$('timer2.Text_5').setString((gameData.totalRound - gameData.leftRound) + "/" + gameData.totalRound + "局");
                that.$('row0.mid').removeAllChildren();
                that.$('row1.mid').removeAllChildren();
                that.$('row2.mid').removeAllChildren();
                that.$('row3.mid').removeAllChildren();
                for (var i = 0; i < 4; i++) {
                    if (that.roomState == that.roomStateType.ROOM_STATE_CREATED)
                        that.$('info' + i).runAction(cc.sequence(
                            cc.moveTo(0.5, that.posConf.headPosBak[i]),
                            cc.delayTime(1.0),
                            cc.callFunc(that.createVideoView())));
                    else
                        that.$('info' + i).setPosition(that.posConf.headPosBak[i]);
                    that.$('info' + i + '.ok').setVisible(false);
                    that.$('info' + i + '.ti').setVisible(false);
                }
            }
            if (state == that.roomStateType.ROOM_STATE_ENDED) {
                if (that.$('btn_queding')) that.$('btn_queding').setVisible(false);
                if (that.$('btn_quxiao')) that.$('btn_xuanzewancheng').setVisible(false);
                if (that.$('btn_xuanzewancheng')) that.$('btn_xuanzewancheng').setVisible(false);
                this.hideChiPengGangHu();
                this.hideArrow();
                that.disabledChuPaiIdMap = {};
                that.lianging = false;
                that.afterLianging = false;
                that.hideGangStep = 0;
                that.hideGangArr = [];
                that.hidedGangArr = [];
                that.hideGangChupaiArr = [];
            }
            that.roomState = state;
        },
        setDuiArr: function (row, duiArr) {
            var that = this;
            for (var j = 0; j < 4; j++) {
                var g = that.$('row' + row + '.g' + j);
                if (g && g.isVisible())
                    g.setVisible(false);
            }
            for (var j = 0; j < duiArr.length; j++) {
                var dui = duiArr[j];
                if (dui.type == 1) this.setGChi(row, j, dui['pai_arr'], dui['from_uid']);
                if (dui.type == 2) this.setGPeng(row, j, dui['pai_arr'][0], dui['from_uid']);
                if (dui.type == 3) this.setGGang(row, j, dui['pai_arr'][0], dui['pai_arr'][0], dui['from_uid']);
                if (dui.type == 4) this.setGGang(row, j, dui['pai_arr'][0], 0, dui['from_uid']);
                if (dui.type == 5) this.setGHide(row, j);
            }
        },
        clearTable4StartGame: function (isInitPai, isReconnect, reconnectData) {
            var that = this;

            this.onPlayerEnterExit();
            if (isInitPai) {
                that.forRows(function (i) {
                    var a0 = that.$('row' + i + '.a0');
                    if (a0.getPosition().x != that.posConf.paiA0PosBak[i].x || a0.getPosition().y != that.posConf.paiA0PosBak[i].y) {
                        a0.setPosition(that.posConf.paiA0PosBak[i]);
                        for (var j = 1; j < 13; j++) {
                            var node = that.$('row' + i + '.a' + j);
                            if (i == 0 || i == 2) node.setPositionX(that.posConf.paiADistance[i] * j + a0.getPositionX());
                            if (i == 1 || i == 3) node.setPositionY(that.posConf.paiADistance[i] * j + a0.getPositionY());
                        }
                    }
                });
                for (var i = 0; i < 4; i++) {
                    for (var j = 0; j < 4; j++) {
                        this.getPai(i, j).setVisible(false);
                    }
                    for (var k = 0; k < 4; k++) {
                        var g = that.$('row' + i + '.g' + k);
                        if (g)
                            g.setVisible(false);
                    }
                    for (var k = 0; k < 4; k++) {
                        this.getGPai(i, 0, k).idx = k;
                    }
                    that.$('row' + i + '.c0.b0').setVisible(false);
                    that.$('row' + i + '.c0.b1').setVisible(false);
                    that.$('row' + i + '.c0.b10').setVisible(false);
                }
                that.forRows(function (i) {
                    for (var j = 0; j < 14; j++) {
                        this.getPai(i, j).setOpacity(0);
                    }
                    var c0 = that.$('row' + i + '.c0');
                    if (i == 0)
                        c0.setLocalZOrder(50);
                    for (var j = 0; j < 60; j++) {
                        var t = that.$('b' + j, c0);
                        if (t) {
                            t.idx = j;
                            t.setVisible(false);
                        }
                    }
                });
                that.setHuTipVisible(false);
            }

            that.$('cpghg').setVisible(false);
            that.$('timer').setVisible(false);

            if (isReconnect) {
                that.hasChupai = reconnectData['has_chu'];
                that.setZhuang(that.uid2position[gameData.zhuangUid]);
                that.leftPaiCnt = reconnectData['left_pai_num'];
                that.$('timer2.Text_2').setString(that.leftPaiCnt);
                var playerPaiArr = reconnectData['player_pai'];
                for (var i = 0; i < playerPaiArr.length; i++) {
                    var playerPai = playerPaiArr[i];
                    var isOffline = !!playerPai['is_offline'];
                    if (isOffline)
                        this.playerOnloneStatusChange(that.uid2position[playerPai.uid], isOffline);
                    var row = that.uid2position[playerPai.uid];
                    if (row != 2
                        && that.roomState == that.roomStateType.ROOM_STATE_ONGOING
                        && playerPai['pai_arr'].length == 0) {
                        for (var j = 0; j < playerPai['cur_pai_num']; j++)
                            playerPai['pai_arr'].push(0);
                    }
                    if (row == 2 && playerPaiArr[i]['is_ting']) {
                        that.afterLianging = true;
                    }
                    if (that.$('info' + row + '.liang'))
                        that.$('info' + row + '.liang').setVisible(playerPaiArr[i]['is_ting']);
                    that.setPaiArrOfRow(row, playerPai['pai_arr'], (row != 2), (row != 2), playerPai['liang_pai_arr']);
                    var liangPaiArr = playerPai['liang_pai_arr'] || [];
                    for (var j = 0; j < liangPaiArr.length; j++)
                        that.disabledChuPaiIdMap[liangPaiArr[j]] = true;
                    var usedPaiArr = playerPaiArr[i]['used_pai_arr'];
                    for (var j = 0; j < usedPaiArr.length; j++)
                        this.addUsedPai(row, usedPaiArr[j]);
                    var duiArr = playerPaiArr[i]['dui_arr'];
                    this.setDuiArr(row, duiArr);

                    var isZixuanpiao = !!playerPaiArr[i]['is_zixuanpiao'];
                    var isSpf = !!playerPaiArr[i]['spf'];
                    var piao = playerPai['piao'] || 0;

                    var spBs = that.$('info' + row + '.sp_piao');
                    if (spBs) {
                        spBs.setVisible(isZixuanpiao && isSpf);
                        if (piao == 0) {
                            spBs.setString('不飘');
                        } else {
                            spBs.setString('飘' + piao + '分');
                        }
                    }
                    this.createVideoView();
                }

                that.forRows(function (i) {
                    this.recalcPos(i);
                });

                if (that.roomState == that.roomStateType.ROOM_STATE_ONGOING) {
                    this.throwTurn(that.uid2position[reconnectData['turn_uid']]);
                    this.enableChuPai();
                }
                else if (that.roomState == that.roomStateType.ROOM_STATE_ENDED) {
                    for (var i = 0; i < playerPaiArr.length; i++) {
                        var playerPai = playerPaiArr[i];
                        var isReady = !!playerPai['is_ready'];
                        if (isReady)
                            that.setReady(playerPai['uid']);
                    }
                }

                var isSelectPiaoFinished = (_.isUndefined(playerPaiArr[0]['spf']) ? true : playerPaiArr[0]['spf']);
                if (!isSelectPiaoFinished) {
                    that.forRows(function (i) {
                        for (var j = 0; j < 14; j++)
                            that.getPai(i, j).setVisible(false);
                    });
                }
            }
            else if (isInitPai) {
                that.forRows(function (i) {
                    this.recalcPos(i);
                });
            }
            gameData.huTipData = null;
            that.$('hu_type_layer').setVisible(false);
        },
        xiangTongPaiBianHui: function (paiId) {
            var that = this;
            for (var i = 0; i < 4; i++) {
                if (this.allCache[i]) {
                    for (var j = 0; j < this.allCache[i].length; j++) {
                        var obj = this.allCache[i][j];
                        if (obj.pai == paiId) {
                            Filter.grayRed(that.$('row' + i + '.c0.b' + obj.idx));
                        }
                        else {
                            Filter.remove(that.$('row' + i + '.c0.b' + obj.idx));
                        }
                    }
                }
            }
        },
        gangChiXiangTongPai: function (paiId) {
            var that = this;
            if (this.allChiPengGangCache) {
                for (var i = 0; i < 4; i++) {
                    if (this.allChiPengGangCache[i]) {
                        for (var j = 0; j < this.allChiPengGangCache[i].length; j++) {
                            var pai = this.allChiPengGangCache[i][j];
                            if (pai.paiId) {
                                if (pai.paiId == paiId) {
                                    Filter.grayRed(pai);
                                }
                                else {
                                    Filter.remove(pai);
                                }
                            }
                        }
                    }
                }
            }
        },
        sendChuPai: function (row, idx, paiId) {
            var that = this;
            network.stop([3007, 3008, 4002, 4020, 4990]);
            network.send(4002, {room_id: gameData.roomId, pai_id: paiId, idx: idx});
            if (gameData.mapId == app.map_id.YIYANG_SUOGANGZI) {
                that.xiangTongPaiBianHui(-1);
                that.gangChiXiangTongPai(-1);
            }
            that.hasChupai = true;
            var paiArr = that.getPaiArr();
            removeObjArray(paiArr, paiId);
            that.chuPai(row, idx, paiId, paiArr);

            //听牌提示
            if(this.hupaiTipData){
                var hupaiCards = this.hupaiTipData["" + paiId];
                if(hupaiCards && hupaiCards.length > 0){
                    this._HuTipUnit.initHuPaiTishiLayer(hupaiCards);
                }else{
                    var hupai_tip = this._HuTipUnit;
                    hupai_tip.setVisible(false);
                    this.hupaiTipData = null;
                }
            }
            this.HuCardTip(null, null, false);
        },
        chuPai: function (row, idx, paiId, paiArr, liangPaiArr) {
            var CHUPAI_MID_NODE_SCALE_MAP = {0: 1.2, 2: 1.2, 1: 1.2, 3: 1.2};
            var that = this;
            if (that.liangStep == 2) {
                that.liangStep = 0;
                that.downPai(row, idx);
                return;
            }
            if (row != 2 && !that.isReplay)
                idx = 13;

            var usedPai = this.addUsedPai(row, paiId);
            that.playerOnloneStatusChange(row, false);
            var pai = this.getPai(row, idx);
            //that.$('row' + that.uid2position[uid] + '.mid')
            var midNode = that.$('row' + row + '.mid');
            var positionBak = pai.getPosition();
            var scaleBak = pai.getScaleX();
            pai.setVisible(false);

            //出牌动画
            var delayDuration = 1000;

            var _paiBg = new cc.Sprite(res.mjbg);
            _paiBg.setScale(CHUPAI_MID_NODE_SCALE_MAP[row] / midNode.getParent().getScaleX());
            _paiBg.setName('paiBg');
            _paiBg.setOpacity(188);
            midNode.addChild(_paiBg);

            var _pai = new cc.Sprite();
            _pai.setName('pai');
            midNode.addChild(_pai);

            var paiName = that.getPaiNameByRowAndId(2, paiId, false, false);
            that.setSpriteFrameByName(_pai, paiName, 'majiang/pai');
            _pai.setScale(CHUPAI_MID_NODE_SCALE_MAP[row] / midNode.getParent().getScaleX());
            _pai.setVisible(true);
            _paiBg.setVisible(true);
            var fangda = settingData.zoom;
            if (fangda) {
                setTimeout(function () {
                    _pai.removeFromParent(true);
                    _paiBg.removeFromParent(true);
                },delayDuration);
            } else {
                _pai.removeFromParent(true);
                _paiBg.removeFromParent(true);
            }
            that.setPaiArrOfRow(row, paiArr, (row != 2), (row != 2), []);

            if (row == 2) {
                pai.setPosition(that.posConf.paiPos[2][idx]);
                pai.setScale(that.posConf.paiA0ScaleBak[row][0], that.posConf.paiA0ScaleBak[row][1]);
                that.upPai(row, -1);
                that.recalcPos(row);
                that.showArrow(usedPai, row);
                that.resetPaiState();
                that.checkPaiAmount();
                that.setPaiArrOfRow(row, paiArr, (row != 2), (row != 2), liangPaiArr);
                that.hideChiPengGangHu();
            }
            else {
                pai.setPosition(positionBak);
                pai.setScale(scaleBak);

                that.setPaiArrOfRow(row, paiArr, (row != 2), (row != 2), liangPaiArr);
                that.recalcPos(row);
                that.showArrow(usedPai, row);
            }
            that.playEffect('vCardOut');
            that.playEffect('vp' + paiId, that.position2sex[row]);
            network.start();
        },

        checkPaiPos: function (row) {
            var that = this;
            for (var j = 0; j < 14; j++) {
                var pai = this.getPai(row, j);
                if (!pai.isUpping && !pai.isDowning)
                    pai.setPosition(that.posConf.paiPos[2][j].x, (pai.isUp ? that.posConf.upPaiPositionY : that.posConf.downPaiPositionY));
            }
        },
        upPai: function (row, idx) {
            var that = this;
            this.checkPaiPos(row);
            if (that.liangStep == 2 && idx >= 0) {
                var pai = that.getPai(row, idx);
                if (pai.isUp && !pai.isDowning) {
                    pai.isDowning = true;
                    pai.runAction(cc.sequence(
                        cc.moveTo(that.UP_PAI_TIME, pai.getPositionX(), (!pai.isUp ? that.posConf.upPaiPositionY : that.posConf.downPaiPositionY))
                        , cc.callFunc(function () {
                            pai.isUp = false;
                            pai.isDowning = false;
                        })
                    ));
                }
                else if (!pai.isUpping) {
                    pai.isUpping = true;
                    pai.runAction(cc.sequence(
                        cc.moveTo(that.UP_PAI_TIME, pai.getPositionX(), (!pai.isUp ? that.posConf.upPaiPositionY : that.posConf.downPaiPositionY))
                        , cc.callFunc(function () {
                            pai.isUp = true;
                            pai.isUpping = false;
                        })
                    ));
                }
                return;
            }
            for (var i = 0; i < 14; i++) {
                (function (j) {
                    var pai = that.getPai(row, j);
                    if (idx == j && pai.isUp) {
                        that.sendChuPai(row, idx, pai.paiId);
                        pai.isUp = false;
                    }
                    else if (idx == j && !pai.isUp && !pai.isUpping) {
                        pai.isUpping = true;
                        pai.runAction(cc.sequence(
                            cc.moveTo(that.UP_PAI_TIME, pai.getPositionX(), (!pai.isUp ? that.posConf.upPaiPositionY : that.posConf.downPaiPositionY))
                            , cc.callFunc(function () {
                                pai.isUp = true;
                                pai.isUpping = false;
                            })
                        ));
                    }
                    else if (idx != j && pai.isUp && !pai.isDowning) {
                        pai.isDowning = true;
                        pai.runAction(cc.sequence(
                            cc.moveTo(that.UP_PAI_TIME, pai.getPositionX(), (!pai.isUp ? that.posConf.upPaiPositionY : that.posConf.downPaiPositionY))
                            , cc.callFunc(function () {
                                pai.isUp = false;
                                pai.isDowning = false;
                            })
                        ));
                    }
                })(i);
            }
        },
        downPai: function (row, idx) {
            var that = this;
            this.checkPaiPos(row);
            var pai = that.getPai(row, idx);
            if (!pai.isUp || pai.isDowning)
                return;
            pai.isDowning = true;
            pai.runAction(cc.sequence(
                cc.moveTo(that.UP_PAI_TIME, pai.getPositionX(), (!pai.isUp ? that.posConf.upPaiPositionY : that.posConf.downPaiPositionY))
                , cc.callFunc(function () {
                    pai.isUp = false;
                    pai.isDowning = false;
                })
            ));
        },
        enableChuPai: function () {
            var that = this;
            if (that.enableChupaiCnt > 0)
                return;
            that.enableChupaiCnt++;

            var that = this;

            var curPaiIdx = -1;
            var beganTime, beganPosition;
            var isUp, paiIdx, paiId;
            var positionBak;
            var safeY;
            var toNodeDelta = {};
            var chupaiListener = cc.EventListener.create({
                event: cc.EventListener.TOUCH_ONE_BY_ONE,
                swallowTouches: true,
                onTouchBegan: function (touch, event) {
                    if (that.hasChupai || !that.isMyTurn() || that.afterLianging || that.disableChupai || that.roomState != that.roomStateType.ROOM_STATE_ONGOING)
                        return;



                    for (var k = 0; k < 14; k++)
                        if (that.getPai(2, k).getNumberOfRunningActions() > 0)
                            return false;

                    var pai, _curPaiIdx = -1;
                    for (var i = 0; i < 14; i++) {
                        pai = that.getPai(2, i);
                        if (!pai.isVisible())
                            continue;
                        if (TouchUtil.isTouchMe(pai, touch, event, null)) {
                            _curPaiIdx = i;
                            break;
                        }
                    }
                    if ((curPaiIdx >= 0 && _curPaiIdx != curPaiIdx) || !(pai.getNumberOfRunningActions() == 0 || !pai.isUpping && !pai.isDowning) || !pai.isLiang)
                        return false;

                    curPaiIdx = _curPaiIdx;

                    if (curPaiIdx >= 0) {
                        // for (var k = 0; k < 14; k++)
                        //     if (that.getPai(2, k).getNumberOfRunningActions() > 0)
                        //         return false;
                        if (gameData.huTipData) {
                            that.showTishiTip(gameData.huTipData);
                            // console.log("333");
                        }
                        that.playEffect('vCardClick');

                        beganTime = getCurrentTimeMills();

                        // back up
                        pai.positionBak = pai.getPosition();
                        pai.scaleBak = pai.getScaleX();

                        isUp = pai.isUp;
                        if (!isUp || that.liangStep == 2)
                            that.upPai(2, pai.idx);
                        if (pai.hucards) {
                            var jiaoSp = pai.getChildByName('hucardSprite');
                            if (jiaoSp && jiaoSp.isVisible())
                                that.HuCardTip(pai.hucards, pai.getPositionX(), true);
                        }

                        paiIdx = pai.idx;
                        paiId = pai.paiId;
                        positionBak = _.clone(that.posConf.paiPos[2][curPaiIdx]);
                        positionBak.y = (true || isUp ? that.posConf.upPaiPositionY : that.posConf.downPaiPositionY);
                        beganPosition = touch.getLocation();
                        safeY = pai.getBoundingBox().height;
                        var a = touch.getLocation();
                        var b = pai.convertToNodeSpace(touch.getLocation());
                        toNodeDelta.x = a.x - b.x;
                        toNodeDelta.y = a.y - b.y;
                        if (gameData.mapId == app.map_id.YIYANG_SUOGANGZI) {
                            that.xiangTongPaiBianHui(paiId);
                            that.gangChiXiangTongPai(paiId);
                        }
                    }

                    return curPaiIdx >= 0;
                },
                onTouchMoved: function (touch, event) {
                    if (curPaiIdx < 0)
                        return;

                    var pai = that.getPai(2, curPaiIdx);
                    if (!pai.isLiang)
                        return;

                    if (beganPosition) {
                        var p = touch.getLocation();
                        p.x -= toNodeDelta.x;
                        p.y -= toNodeDelta.y;
                        if (p.y < safeY) {
                            if (pai.getNumberOfRunningActions() <= 0)
                                pai.setPosition(positionBak);
                            return;
                        }
                        p = pai.convertToNodeSpace(touch.getLocation());
                        p.x += pai.getPositionX() - pai.getBoundingBox().width / 2;
                        p.y += pai.getPositionY() - pai.getBoundingBox().height / 2;
                        pai.setPosition(p);
                    }
                },
                onTouchEnded: function (touch, event) {
                    that.HuCardTip(null, null, false);
                    if (curPaiIdx < 0)
                        return;

                    var pai = that.getPai(2, curPaiIdx);
                    if (beganPosition) {
                        var p = touch.getLocation();
                        p.x -= toNodeDelta.x;
                        p.y -= toNodeDelta.y;
                        var now = getCurrentTimeMills();
                        var isSend = (p.y < safeY && isUp && Math.abs(now - beganTime) < 168) || (p.y > safeY);
                        if (isSend) {
                            if ((gameData.mapId == app.map_id.YIYANG || gameData.mapId == app.map_id.YIYANG_SUOGANGZI) && that.hideGangStep == 2) {
                                that.hideGangStep = 0;
                                that.afterLianging = true;
                                setTimeout(function () {
                                    that.playChiPengGangHuAnim(2, that.opType.OP_TING);
                                    if (that.$('info' + 2 + '.liang'))
                                        that.$('info' + 2 + '.liang').setVisible(true);
                                    playEffect('vting', that.position2sex[2]);
                                }, 100);
                            }
                            if (that.liangStep == 0 && that.hideGangStep == 0) {
                                that.sendChuPai(2, paiIdx, paiId);
                                that.setHuTipVisible(false);
                            }
                        }
                        else {
                            that.checkPaiPos(2);
                            setTimeout(function () {
                                curPaiIdx = -1;
                                beganPosition = null;
                            }, parseInt(that.UPDOWNPAI_ANIM_DURATION * 100));
                        }
                    }
                    curPaiIdx = -1;
                    beganPosition = null;
                    return false;
                }
            });
            that.HuCardTip(null, null, false);
            return cc.eventManager.addListener(chupaiListener, that.$("row2"));
        },
        countDown: function () {
            var that = this;
            var timer = null;
            return function (seconds) {
                if (that.isReplay) {
                    that.$('timer.sec').setString('');
                    return;
                }
                if (timer) {
                    clearInterval(timer);
                    timer = null;
                }
                that.$('timer.sec').setString(seconds);
                timer = setInterval(function () {
                    var sec = that.$('timer.sec');
                    if (!cc.sys.isObjectValid(sec)) {
                        if (timer)
                            clearInterval(timer);
                        return;
                    }
                    if (!sec) {
                        clearInterval(timer);
                        timer = null;
                        return;
                    }
                    if (seconds > 0) {
                        --seconds;
                        sec.setString(seconds < 10 ? "0" + seconds : seconds);
                    }
                    if (seconds == 0) {
                        if (that.turnRow == 2 && !that.hasChupai)
                            DeviceUtil.vibrate();
                        clearInterval(timer);
                    }
                }, 1000);
            }
        },
        closePai: function (paiId) {

        },
        setPaiArrOfRow: function (row, paiArr, isLittle, isStand, liangPaiArr, liangAll, huPaiId) {
            var that = this;
            liangPaiArr = liangPaiArr || [];
            if (that.isReplay || that.roomState == that.roomStateType.ROOM_STATE_ENDED) {
                liangPaiArr = [];
            }
            if (row == 2)
                _.pull(paiArr, 0);
            paiArr.sort(compareTwoNumbers);
            if (gameData.mapId == app.map_id.ZHUANZHUAN || gameData.mapId == app.map_id.CHENZHOU || gameData.mapId == app.map_id.CHANGDE || gameData.mapId == app.map_id.HONGZHONG) {
                var oldSize = paiArr.length;
                _.pull(paiArr, 32);
                if (paiArr.length != oldSize) {
                    var t = paiArr.length;
                    for (var j = 0; j < oldSize - t; j++)
                        paiArr.splice(0, 0, 32);
                }
            }

            if (huPaiId) {
                var idx = paiArr.indexOf(huPaiId);
                if (idx >= 0) {
                    paiArr.splice(idx, 1);
                    paiArr.push(huPaiId);
                }
            }
            var lastPai = null;
            for (var j = 0; j < paiArr.length; j++) {
                lastPai = this.setPai(row, j, paiArr[j], isLittle, isStand, true);
                lastPai.setOpacity(255);
            }
            for (; j < 14; j++)
                this.setPai(row, j, 0, isLittle, isStand, false);
            liangPaiArr.sort(compareTwoNumbers);
            if (typeof liangPaiArr !== 'undefined') {
                var cond = (row == 2);
                if (gameData.mapId == app.map_id.CHANGSHA)
                    cond = (cond && that.afterLianging);
                else
                    cond = (cond && that.hideGangStep > 0);
                if (cond) {
                    if (gameData.mapId == app.map_id.CHANGSHA) {
                        var pai = this.getPai(2, 13);
                        Filter.grayMask(pai);
                        pai.isLiang = false;
                    }
                    for (var i = 0; i < paiArr.length; i++) {
                        var pai = this.getPai(2, i);
                        Filter.grayMask(pai);
                        pai.isLiang = false;
                    }
                    for (var j = 0; j < liangPaiArr.length; j++) {
                        for (var i = 0; i < paiArr.length; i++) {
                            var pai = this.getPai(2, i);
                            if (pai.paiId == liangPaiArr[j] && !pai.isLiang) {
                                pai.isLiang = true;
                                Filter.remove(pai);
                                if (!liangAll)
                                    break;
                            }
                        }
                    }
                }
                else {
                    if (row == 1 || row == 0)
                        for (var j = 0; j < liangPaiArr.length; j++)
                            this.setPai(row, j, liangPaiArr[j], isLittle, isStand, true);
                    if (row == 3)
                        for (var j = 0; j < liangPaiArr.length; j++)
                            this.setPai(row, paiArr.length - liangPaiArr.length + j, liangPaiArr[j], isLittle, isStand, true);
                }
            }
            else if (false && that.disabledChuPaiIdMap) {
                for (var i = 0; i < paiArr.length; i++) {
                    if (that.disabledChuPaiIdMap[paiArr[i]]) {
                        var pai = this.getPai(2, i);
                        Filter.grayMask(pai);
                        pai.isLiang = false;
                    }
                }
            }
            if (huPaiId) {
                lastPai.setOpacity(168);
                this.recalcPos(row);
            }
        },
        mopai: function (row, paiId, paiArr, liangPaiArr) {
            var that = this;
            if (row == 2) {
                that.hasChupai = false;
                this.setPaiArrOfRow(2, paiArr, false, false, liangPaiArr);
            }
            var func = function () {
                that.throwTurn(row);
                if (row == 2)
                    that.recalcPos(2);
                that.countDown(12);
            };
            this.setPai(row, 13, (row == 2 || that.isReplay ? paiId : 0), (row != 2), (row != 2), true)
                .runAction(cc.fadeIn(that.MOPAI_ANIM_DURATION));
            func();
        },
        showChiPengGangHu: function (row, paiId, chi, peng, gang, hu, ting, data) {
            var that = this;

            if (!that.isReplay) {
                var _opPaiIdArr = {};

                var children = that.$('cpghg').getChildren();
                for (var i = 0; i < children.length; i++) {
                    children[i].setVisible(false);
                }
                if (gameData.mapId == app.map_id.CHANGSHA) {
                    if (!gang) {
                        var nextGang = data['next_gang'];
                        if (nextGang) {
                            _opPaiIdArr[that.opType.OP_GANG] = nextGang;
                            _opPaiIdArr[that.opType.OP_TING] = nextGang;
                            gang = 1;
                        }
                    }

                    ting = gang;
                }
                var sum = (chi || 0) + (peng || 0) + (gang || 0) + (hu || 0) + (ting || 0) + 1;
                that.$('cpghg.chi').setVisible(false);
                that.$('cpghg.peng').setVisible(false);
                that.$('cpghg.gang').setVisible(false);
                that.$('cpghg.hu').setVisible(false);
                that.$('cpghg.ting').setVisible(false);
                var nodeArr = [], opArr = [];
                if (chi) {
                    nodeArr.push(that.$('cpghg.chi'));
                    opArr.push(that.opType.OP_CHI);
                }
                if (peng) {
                    nodeArr.push(that.$('cpghg.peng'));
                    opArr.push(that.opType.OP_PENG);
                }
                if (gang) {
                    nodeArr.push(that.$('cpghg.gang'));
                    opArr.push(that.opType.OP_GANG);
                }
                if (hu) {
                    nodeArr.push(that.$('cpghg.hu'));
                    opArr.push(that.opType.OP_HU);
                }
                if (ting) {
                    nodeArr.push(that.$('cpghg.ting'));
                    opArr.push(that.opType.OP_TING);
                }
                nodeArr.splice(0, 0, that.$('cpghg.guo'));
                opArr.splice(0, 0, 0);
                //nodeArr.push(that.$('cpghg.guo'));

                for (var i = 0; i < nodeArr.length; i++) {
                    if (nodeArr[i].getName() != "guo") {
                        var node = that.$('a', nodeArr[i]);
                        if (!node) {
                            var node = duplicateNode(that.$('row2.c0.b0'));
                            node.setName('a');
                            node.setPosition(that.$('n', nodeArr[i]).getPosition());
                            node.setVisible(true);
                            nodeArr[i].addChild(node);
                        }
                        var _paiId = _opPaiIdArr[opArr[i]] || paiId;
                        var paiName = that.getPaiNameByRowAndId(2, _paiId, true);
                        that.setSpriteFrameByName(node, paiName, 'pai');
                        node.paiId = _paiId;
                    }
                    if (nodeArr.length > 5) {
                        nodeArr[i].setPositionX(1100 - (i % 5) * 240);
                        nodeArr[i].setPositionY(i < nodeArr.length % 5 ? 400.00 : 214);
                    }
                    else {
                        nodeArr[i].setPositionX(1100 - (i % 5) * 240);
                        nodeArr[i].setPositionY(214);
                    }

                    nodeArr[i].setVisible(true);
                }

                if (gameData.mapId == app.map_id.CHANGSHA && ting) {
                    that.$('cpghg.ting').setTexture(majiang_hn.res.ChiPengGangHuUnit_bu);
                }

                if ((gameData.mapId == app.map_id.YIYANG || gameData.mapId == app.map_id.YIYANG_SUOGANGZI) && ting) {
                    that.$('cpghg.ting').setTexture(majiang_hn.res.ChiPengGangHuUnit_ting);
                }

                chi && TouchUtil.setOnclickListener(that.$('cpghg.chi'), function () {
                    var _paiId = that.$('cpghg.chi.a').paiId || paiId;
                    that.showChiLayer(_paiId);
                });

                peng && TouchUtil.setOnclickListener(that.$('cpghg.peng'), function () {
                    var _paiId = that.$('cpghg.peng.a').paiId || paiId;
                    that.sendChiPengGang(that.opType.OP_PENG, 2, _paiId);
                    that.hideChiPengGangHu();
                });

                ting && TouchUtil.setOnclickListener(that.$('cpghg.ting'), function () {
                    var _paiId = that.$('cpghg.ting.a').paiId || paiId;
                    if (gameData.mapId == app.map_id.CHANGSHA) {
                        that.sendChiPengGang(that.opType.OP_GANG, 2, _paiId);
                        that.hideChiPengGangHu();
                    }
                    else if (gameData.mapId == app.map_id.YIYANG || gameData.mapId == app.map_id.YIYANG_SUOGANGZI) {
                        that.hideChiPengGangHu();
                        network.send(4014, {
                            room_id: gameData.roomId,
                            uid: gameData.uid
                        });
                    }
                });

                hu && TouchUtil.setOnclickListener(that.$('cpghg.hu'), function () {
                    var _paiId = that.$('cpghg.hu.a').paiId || paiId;
                    do {
                        if (gameData.mapId == app.map_id.CHANGSHA) {
                            if (that.selectingXiaohu && that.leftPaiCnt == 55) {
                                that.sendChiPengGang(that.opType.OP_XIAOHU, 2, _paiId);
                                that.hideChiPengGangHu();
                                break;
                            }
                        }

                        that.sendChiPengGang(that.opType.OP_HU, 2, _paiId);
                        that.hideChiPengGangHu();
                    } while (false);
                });

                gang && TouchUtil.setOnclickListener(that.$('cpghg.gang'), function () {
                    var _paiId = that.$('cpghg.gang.a').paiId || paiId;
                    if (gameData.mapId == app.map_id.CHANGSHA) {
                        var isKaigang = data['kaigang'];
                        if (!isKaigang) {
                            showMessageBox("确定要【开杠】吗?", function () {
                                that.sendChiPengGang(that.opType.OP_KAIGANG, 2, _paiId);
                                that.hideChiPengGangHu();
                            }, function () {
                            });
                        }
                        else {
                            that.sendChiPengGang(that.opType.OP_KAIGANG, 2, _paiId);
                            that.hideChiPengGangHu();
                        }
                    }
                    else {
                        that.sendChiPengGang(that.opType.OP_GANG, 2, _paiId);
                        that.hideChiPengGangHu();
                    }
                });

                //见炮必胡  只能点胡
                if(gameData.wanfaDesp.indexOf('见炮必胡') >= 0 && hu){
                    that.$('cpghg.guo').setVisible(false);
                }
                TouchUtil.setOnclickListener(that.$('cpghg.guo'), function () {
                    if (hu && that.isMyTurn()) {
                        showMessageBox("您当前可以自摸, 确定要点【过】吗?", function () {
                            that.sendChiPengGang(that.opType.OP_PASS, 2, paiId);
                            that.hideChiPengGangHu();
                        }, function () {
                            return;
                        });
                    }
                    else {
                        that.sendChiPengGang(that.opType.OP_PASS, 2, paiId);
                        that.hideChiPengGangHu();
                    }
                });

                that.$('cpghg').setVisible(true);

                this.countDown(12);
            } else {
                if (gameData.mapId == app.map_id.CHANGSHA) {
                    if (!gang) {
                        var nextGang = data['next_gang'];
                        if (nextGang) {
                            gang = 1;
                        }
                    }
                    ting = gang;
                }
                ;
                var cpg = that.$('cpghRep' + row);
                if (!cc.sys.isObjectValid(that) || cpg == null) {
                    return;
                }
                that.$('cpghRep' + row + '.sp_0_1').setVisible(!!chi);
                that.$('cpghRep' + row + '.sp_1_1').setVisible(!!peng);
                that.$('cpghRep' + row + '.sp_2_1').setVisible(!!gang);
                that.$('cpghRep' + row + '.sp_3_1').setVisible(!!hu);
                that.$('cpghRep' + row + '.sp_4_1').setVisible(true);
                that.$('cpghRep' + row + '.sp_5_1').setVisible(!!ting);

                that.$('cpghRep' + row + '.sp_0').setVisible(!chi);
                that.$('cpghRep' + row + '.sp_1').setVisible(!peng);
                that.$('cpghRep' + row + '.sp_2').setVisible(!gang);
                that.$('cpghRep' + row + '.sp_3').setVisible(!hu);
                that.$('cpghRep' + row + '.sp_4').setVisible(false);
                that.$('cpghRep' + row + '.sp_5').setVisible(!ting);

                var pai = that.$('cpghRep' + row + '.sp_pai');
                var paiName = that.getPaiNameByRowAndId(2, paiId, true);
                pai.setScale(0.65, 0.65);
                that.setSpriteFrameByName(pai, paiName, 'pai');
                cpg.setVisible(true);
            }
        },
        showTingLiang: function (row, ting, liang) {
            return;
            var that = this;

            if (!that.isReplay) {
                that.$('tl.ting').setVisible(!!ting);
                that.$('tl.liang').setVisible(!!liang);

                ting && TouchUtil.setOnclickListener(that.$('tl.ting'), function () {
                    that.sendChiPengGang(that.opType.OP_PENG, 2, paiId);
                    that.hideChiPengGangHu();
                });

                liang && TouchUtil.setOnclickListener(that.$('tl.liang'), function () {
                    that.sendChiPengGang(that.opType.OP_PENG, 2, paiId);
                    that.hideChiPengGangHu();
                });

                that.$('tl').setVisible(true);
            } else {
                var cpg = that.$('cpghRep' + row);
                for (var i = 0; i < 6; i++) {
                    if (!cpg.getChildByName("sp1_" + i)) {
                        var sp = new cc.Sprite(res["sp1_" + i]);
                        sp.setPosition(cpg.getChildByName("sp_" + i).getPosition());
                        sp.setName("sp1_" + i);
                        cpg.addChild(sp);
                        sp.setVisible(false);
                    }
                }
                that.$('cpghRep' + row + '.sp1_0').setVisible(!!chi);
                that.$('cpghRep' + row + '.sp1_1').setVisible(!!peng);
                that.$('cpghRep' + row + '.sp1_2').setVisible(!!gang);
                that.$('cpghRep' + row + '.sp1_3').setVisible(!!hu);
                that.$('cpghRep' + row + '.sp1_4').setVisible(true);
                that.$('cpghRep' + row + '.sp1_5').setVisible(false);

                that.$('cpghRep' + row + '.sp_0').setVisible(!chi);
                that.$('cpghRep' + row + '.sp_1').setVisible(!peng);
                that.$('cpghRep' + row + '.sp_2').setVisible(!gang);
                that.$('cpghRep' + row + '.sp_3').setVisible(!hu);
                that.$('cpghRep' + row + '.sp_4').setVisible(false);
                that.$('cpghRep' + row + '.sp_5').setVisible(true);

                var pai = that.$('cpghRep' + row + '.sp_pai');
                var paiName = that.getPaiNameByRowAndId(2, paiId, true);
                pai.setScale(0.65, 0.65);
                that.setSpriteFrameByName(pai, paiName, 'pai');
                cpg.setVisible(true);
            }
        },
        hideChiPengGangHu: function () {
            var that = this;
            that.$('cpghg').setVisible(false);
            if (that.$('chiLayer'))
                that.$('chiLayer').removeFromParent(false);
        },
        /**
         * 发送吃
         */
        sendChi: function (_paiId) {
            var self = this;
            self.showChiLayer(_paiId, function (paiId, oriPaiId) {
                self.sendChiPengGang(self.opType.OP_CHI, 2, paiId, oriPaiId);
            });
        },
        sendChiPengGang: function (op, row, paiId, oriPaiId) {
            var that = this;
            if (that.chiPengGangHuCode == 4052) {
                network.send(4056, {room_id: gameData.roomId, op: op, pai_id: paiId, ori_pai_id: oriPaiId});
                if (that._Ma_KaiGangWindow) {
                    that._Ma_KaiGangWindow.removeFromParent(true);
                    that._Ma_KaiGangWindow = null;
                }
            } else {
                network.send(4003, {room_id: gameData.roomId, op: op, pai_id: paiId, ori_pai_id: oriPaiId});
            }
            that._chiPengGangHuCode = 0;
        },
        playChiPengGangHuAnim: function (row, op, isZimo, isAngang) {
            var that = this;
            var anim_json = isZimo ? majiang_hn.res.zimo_json : {
                1: majiang_hn.res.chi_json    // chi
                , 2: majiang_hn.res.peng_json
                , 3: (gameData.mapId == app.map_id.CHANGSHA) ? majiang_hn.res.bu_json : majiang_hn.res.gang_json
                , 4: majiang_hn.res.hu_json
                , 6: majiang_hn.res.ting_json
                , 7: majiang_hn.res.liang_json
                , 8: majiang_hn.res.baojia_json
                , 9: majiang_hn.res.baodiao_json
                , 10: majiang_hn.res.baoduidao_json
                , 11: majiang_hn.res.baobian_json
                , 50: majiang_hn.res.gang_json
            }[op];

            var infoNode = that.$("info_n" + row);
            if (infoNode.children.length != 0) {
                infoNode.removeAllChildren();
            }
            playAnimScene(infoNode, anim_json, 0, 0, false, function () {
                infoNode.removeAllChildren();
            });
        },
        setReplayProgress: function (cur, total) {
            var that = this;
            var progress = cur / total * 100;
            this.showTip("回放进度: " + progress.toFixed(1) + '%', false);
        },
        setAllPai4Replay: function (data) {
            var that = this;
            for (var uid in data)
                if (data.hasOwnProperty(uid)) {
                    var row = that.uid2position[uid];
                    var paiArr = data[uid]['pai_arr'];
                    this.setPaiArrOfRow(row, paiArr, (row != 2), false);

                    var duiArr = data[uid]['dui_arr'];
                    for (var j = 0; j < duiArr.length; j++) {
                        var dui = duiArr[j];
                        if (dui.type == 1) this.setGChi(row, j, dui['pai_arr'], dui['from_uid']);
                        if (dui.type == 2) this.setGPeng(row, j, dui['pai_arr'][0], dui['from_uid']);
                        if (dui.type == 3) this.setGGang(row, j, dui['pai_arr'][0], dui['pai_arr'][0], data['from_uid']);
                        if (dui.type == 4) this.setGGang(row, j, dui['pai_arr'][0], 0, data['from_uid']);
                        if (dui.type == 5) this.setGHide(row, j);
                    }
                    for (; j < 4 && that.$('row' + row + '.g' + j); j++)
                        that.$('row' + row + '.g' + j).setVisible(false);

                    if (that.$('row' + row + '.g' + 0).isVisible() == 0) {
                        that.$('row' + row + '.a' + 0).setPosition(that.posConf.paiA0PosBak[row]);
                    }

                    var usedArr = data[uid]['used_arr'];
                    for (var j = 0; j < 100; j++) {
                        var pai = that.$('row' + row + '.c0.b' + j);
                        if (pai)
                            pai.setVisible(false);
                    }
                    for (var j = 0; j < usedArr.length; j++) {
                        this.addUsedPai(row, usedArr[j])
                    }

                    this.recalcPos(row);
                }
        },
        setChiPengGangCache: function (row, pai) {
            var that = this;
            if (this.allChiPengGangCache == null) {
                this.allChiPengGangCache = {};
            }
            if (!this.allChiPengGangCache[row]) {
                this.allChiPengGangCache[row] = [];
            }
            this.allChiPengGangCache[row].push(pai);
            cc.log(this.allChiPengGangCache);
        },
        chiPengGangHu: function (op, row, paiId, fromRow, data) {
            var that = this;
            if (that.isReplay) {
                var tmop = op;
                if (gameData.mapId == app.map_id.CHANGSHA) {
                    if (!data["cs_gang"]) {
                        tmop = that.opType.OP_BU;
                    }
                }
                var node = that.$('cpghRep' + row + '.sp_' + (tmop - 1));
                var touch_node = that.$('cpghRep' + row + '.touch_node');
                touch_node.setPosition(node.getPositionX(), node.getPositionY() - 40);
                var touch_sp0 = that.$('cpghRep' + row + '.touch_node.touch0');
                var touch_sp1 = that.$('cpghRep' + row + '.touch_node.touch1');
                touch_sp1.setVisible(false);
                touch_node.setVisible(true);
                touch_node.runAction(cc.sequence(cc.delayTime(0.1), cc.callFunc(function () {
                    touch_sp0.setVisible(false);
                    touch_sp1.setVisible(true);
                }), cc.delayTime(0.818), cc.callFunc(function () {
                    touch_node.setVisible(false);
                    that.$('cpghRep' + row).setVisible(false);
                })));
            }

            var j;
            for (j = 0; j < 4; j++) {
                var g = that.$('row' + row + '.g' + j);
                if (!g || !that.$('row' + row + '.g' + j).isVisible())
                    break;
            }

            var paiArr = this.getPaiArr();

            if (op == that.opType.OP_CHI) {
                var oriPaiId = data['ori_pai_id'];
                this.setGChi(row, j, paiId, oriPaiId, data['from_uid']);
                that.hasChupai = false;
                this.removeOneTopUsedPai(fromRow);
                this.playChiPengGangHuAnim(row, op);
                playEffect('vchi', that.position2sex[row]);
            } else if (op == that.opType.OP_PENG || op == that.opType.OP_GANG) {
                var duiArr = (data['dui_arr'] || []);
                var isJiagang = (data['is_jiagang'] || 0);

                if (op == that.opType.OP_PENG) {
                    this.setGPeng(row, j, paiId, data['from_uid']);
                    _.remove(paiArr, function (n) {
                        return n == paiId;
                    });
                    that.hasChupai = false;
                    this.removeOneTopUsedPai(fromRow);
                    this.playChiPengGangHuAnim(row, op);
                    playEffect('vpeng', that.position2sex[row]);
                }
                else if (op == that.opType.OP_PENG || op == that.opType.OP_GANG) {
                    var isAngang = (row == fromRow && !isJiagang);
                    var upPaiId = paiId;
                    var downPaiId = (isAngang ? 0 : paiId);

                    if (duiArr)
                        this.setDuiArr(row, duiArr);
                    else {
                        if (isAngang || !isJiagang) {   // angang or minggang
                            this.setGGang(row, j, upPaiId, downPaiId, data['from_uid']);
                        }
                        else if (isJiagang) {
                            this.setGJiaGang(row, paiId, data['from_uid']);
                        }
                    }

                    if (row != fromRow)
                        this.removeOneTopUsedPai(fromRow);

                    _.remove(paiArr, function (n) {
                        return n == paiId;
                    });

                    that.hasChupai = false;
                    if (row == 2 || isJiagang)
                        that.hasChupai = true;

                    if (gameData.mapId == app.map_id.CHANGSHA) {
                        if (data["cs_gang"]) {
                            this.playChiPengGangHuAnim(row, that.opType.OP_KAIGANG, false, isAngang);
                            playEffect(isAngang ? 'vangang' : 'vgang', that.position2sex[row]);
                        } else {
                            this.playChiPengGangHuAnim(row, op, false, isAngang);
                            playEffect('vbu', that.position2sex[row]);
                        }
                    } else {
                        this.playChiPengGangHuAnim(row, op, false, isAngang);
                        playEffect(isAngang ? 'vangang' : 'vgang', that.position2sex[row]);
                    }
                }

                this.hideChiPengGangHu();

                if (!isJiagang && !duiArr)
                    that.$('row' + row + '.g' + j).setVisible(true);
            }
            else if (op == that.opType.OP_HU) {
                var isZimo = (data['is_zimo'] || 0);

                if (fromRow == 2)
                    this.hideChiPengGangHu();

                if (!isZimo)
                    this.removeOneTopUsedPai(fromRow, paiId);
                this.playChiPengGangHuAnim(row, op, isZimo);
                if (gameData.mapId != app.map_id.CHANGSHA) {
                    playEffect(isZimo ? 'vzimo' : 'vhu_pao', that.position2sex[row]);
                }
            }
            else if (op == that.opType.OP_TING) {
                that.$('info' + fromRow + '.liang').setVisible(false);
                this.playChiPengGangHuAnim(row, op);
                playEffect('vting', that.position2sex[row]);
            }
            else {
                return;
            }

            this.playerOnloneStatusChange(row, false);

            var _paiArr = (data['pai_arr'] || []);
            var liangPaiArr = (data['liang_pai_arr'] || []);
            var paiCnt = (data['pai_cnt'] || 0);
            var n = paiCnt - _paiArr.length;
            for (var i = 0; i < n; i++)
                _paiArr.push(0);
            if (op == that.opType.OP_HU)
                that.curHuPaiId = paiId;
            this.setPaiArrOfRow(row, _paiArr, (row != 2), (op != that.opType.OP_HU), liangPaiArr, false, that.curHuPaiId);

            if (op == that.opType.OP_HU && _.isObject(data['player'])) {
                var playerMap = data['player'];
                for (var uid in playerMap) {
                    var tRow = that.uid2position[uid];
                    var tPaiArr = playerMap[uid]['pai_arr'];
                    var tDuiArr = playerMap[uid]['dui_arr'];
                    if (tRow != 2) {
                        for (var i = 0; i < tPaiArr.length; i++)
                            tPaiArr[i] = 0;
                    }
                    this.setDuiArr(tRow, tDuiArr);
                    this.setPaiArrOfRow(tRow, tPaiArr, (tRow != 2), (tRow != 2));
                    this.recalcPos(tRow);
                }
            }

            if (op != that.opType.OP_HU) {
                this.setPai(row, 13, 0);
                this.getPai(row, 13).runAction(cc.fadeOut(0));
            }
            this.recalcPos(row);
            this.checkPaiAmount();
        },
        fapai: function (paiArr) {
            var that = this;
            _.pull(paiArr, 0);
            paiArr.sort(compareTwoNumbers);
            that.forRows(function (i) {
                for (var j = 0; j < paiArr.length; j++)
                    this.setPai(i, j, (i == 2 ? paiArr[j] : 0), (i != 2), (i != 2));
                for (; j < 14; j++)
                    this.setPai(i, j, 0, (i != 2), (i != 2), false);
            });
            this.setPai(2, 13, 0, false, false, this.isMyTurn());
            that.forRows(function (i) {
                for (var j = 0; j < 13; j++) {
                    this.getPai(i, j).setVisible(true);
                    this.getPai(i, j).runAction(
                        cc.sequence(cc.delayTime(j * that.FAPAI_ANIM_DELAY), cc.fadeIn(that.FAPAI_ANIM_DURATION))
                    );
                    var pai = this.getPai(i, j);
                    pai.isUp = false;
                    pai.isUpping = false;
                    pai.isDowning = false;
                }
                this.getPai(i, 13).setVisible(false);
                this.getPai(i, 13).isUp = false;
                this.getPai(i, 13).isUpping = false;
                this.getPai(i, 13).isDowning = false;
                this.recalcPos(i);
            });
            this.enableChuPai();

            if (that.$('info0.liang')) that.$('info0.liang').setVisible(false);
            if (that.$('info1.liang')) that.$('info1.liang').setVisible(false);
            if (that.$('info2.liang')) that.$('info2.liang').setVisible(false);
            if (that.$('info3.liang')) that.$('info3.liang').setVisible(false);
            that.hideGangStep = 0;
            that.liangStep = 0;
            that.afterLianging = false;
            that.curHuPaiId = 0;
            this.HuCardTip(null, 0, false);
        },
        showJieSuanWindow: function (data) {
            this.jiesuan(data);
        },
        jiesuan: function (data) {
            var that = this;

            var myScore = 0;
            var players = data.players;
            var fan = 0;
            for (var i = 0; i < players.length; i++) {
                var player = players[i];
                var uid = player['uid'];

                gameData.players[that.position2playerArrIdx[that.uid2position[uid]]].score = player['total_score'];
                that.$('info' + that.uid2position[uid] + '.lb_score').setString(player['total_score'] + 1000);

                fan = Math.max(fan, player['fan']);

                if (uid == gameData.uid) {
                    myScore = player['score'];
                    continue;
                }
                var row = that.uid2position[uid];
                var paiArr = player['pai_arr'];
                if (data['hu_type'] == 2 && player['hu'])
                    this.setPaiArrOfRow(that.uid2position[uid], paiArr, (row != 2), false, [], false, that.curHuPaiId);
                else
                    this.setPaiArrOfRow(that.uid2position[uid], paiArr, (row != 2), false);
            }
            if (gameData.mapId == app.map_id.CHANGSHA) {
                if (fan >= 6) {
                    playEffect('vhu_dfz');
                } else if (data['hu_type'] == 1) {
                    playEffect('vzimo');
                } else if (data['hu_type'] == 2) {
                    playEffect('vhu_pao');
                }
            }
            setTimeout(function () {
                showWindow('Ma_JieSuanHuNanWindow', data, that);
                playEffect(myScore >= 0 ? 'vWin' : 'vLose');
            }, 1000);
        },
        onJiesuanClose: function (isReady) {
            var that = this;
            if(!that.$ || !that.$('btn_zhunbei')){
                return;
            }
            if (isReady || that.isReplay) {
                that.$('btn_zhunbei').setVisible(false);
            } else {
                that.$('btn_zhunbei').setVisible(true);
            }
        },
        zongJiesuan: function (data) {
            var that = this;
            setTimeout(function () {
                showWindow('Ma_ZongJieSuanHuNanWindow', data, that);
            }, 1000);
        },
        showPlayerInfoPanel: function (idx) {
            var that = this;
            if (window.inReview || that.getRoomState() == that.roomStateType.ROOM_STATE_CREATED)
                return;

            if (that.position2playerArrIdx[idx] >= gameData.players.length)
                return;
            var PlayerInfo = gameData.players[that.position2playerArrIdx[idx]];
            network.send(3018, {cmd: 'queryEmoji', uid: gameData.uid, room_id: gameData.roomId});
            showWindow('PlayerInfoInGameWindow', PlayerInfo, that);
        },
        playerOnloneStatusChange: function (row, isOffline) {
            var that = this;
            var offline = that.$('info' + row + '.offline');
            if (offline && cc.sys.isObjectValid(offline))
                offline.setVisible(!!isOffline);
        },
        setZhuang: function (row) {
            var that = this;
            that.$('info0.zhuang').setVisible(false);
            that.$('info1.zhuang').setVisible(false);
            that.$('info2.zhuang').setVisible(false);
            that.$('info3.zhuang').setVisible(false);
            if (that.$('info' + row + '.zhuang'))
                that.$('info' + row + '.zhuang').setVisible(true);
        },
        setBeforeOnCCSLoadFinish: function (cb) {
            var that = this;
            this.beforeOnCCSLoadFinish = cb;
        },
        getBeforeOnCCSLoadFinish: function (cb) {
            var that = this;
            return this.beforeOnCCSLoadFinish;
        },
        setAfterGameStart: function (cb) {
            var that = this;
            this.afterGameStart = cb;
        },
        setReady: function (uid) {
            var that = this;
            var ok = that.$('row' + that.uid2position[uid] + '.mid.ok');
            if (!ok) {
                ok = duplicateNode(that.$('info0.ok'));
                ok.setVisible(true);
                ok.setPosition(cc.p(0, 0));
                that.$('row' + that.uid2position[uid] + '.mid').addChild(ok);
            }
            if (that.uid2playerInfo[uid]) {
                that.uid2playerInfo[uid]['ready'] = 1;
            }
            if (uid == gameData.uid)
                that.$('btn_zhunbei').setVisible(false);
        },
        showToast: function (msg) {
            var that = this;
            var toast = that.$('toast');
            if (!toast) {
                toast = new cc.Sprite(majiang_hn.res.toast_bg_png);
                toast.setName("toast");
                this.addChild(toast);

                var text = new ccui.Text();
                text.setName('text');
                text.setFontSize(30);
                text.setTextColor(cc.color(255, 255, 255));
                text.setPosition(toast.getBoundingBox().width / 2, toast.getBoundingBox().height / 2);
                text.setString(msg);
                toast.setPosition(cc.winSize.width / 2, cc.winSize.height / 2 * 4 / 5);
                toast.addChild(text);
            }
            toast.stopAllActions();
            toast.runAction(cc.sequence(cc.fadeIn(3), cc.fadeOut(0.3)));
            text = toast.getChildByName('text');
            text.runAction(cc.sequence(cc.fadeIn(3), cc.fadeOut(0.3)));
        },
        initMic: function () {
            var that = this;
            var cancelOrSend = false;
            var chatTime = 0;
            var animNode = null;
            var voiceFilename = null;
            var uploadFilename = null;
            TouchUtil.setListeners(that.$('btn_mic'), {
                onTouchBegan: function (node, touch, event) {
                    if (animNode && animNode.getParent()) {
                        animNode.removeFromParent();
                    }

                    cancelOrSend = true;
                    animNode = playAnimScene(that, majiang_hn.res.AnimMic_json, 0, 0, true);
                    chatTime = getCurrentTimeMills();
                    voiceFilename = getCurTimestamp() + '-' + gameData.uid + '-';
                    uploadFilename = voiceFilename;
                    voiceFilename += Math.floor(Math.random() * 100) + '.spx';
                    // console.log(voiceFilename);
                    startVoiceRecord(voiceFilename);
                },
                onTouchMoveIn: function (node, touch, event) {
                    if (!cancelOrSend) {
                        cancelOrSend = true;

                        animNode.removeFromParent();
                        animNode = playAnimScene(that, majiang_hn.res.AnimMic_json, 0, 0, true);
                    }
                },
                onTouchMoveOut: function (node, touch, event) {
                    if (cancelOrSend) {
                        cancelOrSend = false;
                        animNode.removeFromParent();
                        animNode = ccs.load(majiang_hn.res.ChatNotSendNode_json).node;
                        animNode.setPosition(that.getContentSize().width / 2, that.getContentSize().height / 2);
                        that.addChild(animNode);
                    }
                },
                onTouchEndedWithoutCheckTouchMe: function (node, touch, event) {
                    chatTime = getCurrentTimeMills() - chatTime;
                    animNode.removeFromParent();
                    animNode = null;
                    if (cancelOrSend) {
                        if (chatTime > 1000) {
                            stopVoiceRecord(voiceFilename);
                            var interval = null;
                            var checkFunc = function () {
                                var isOpened = isFileOpened(voiceFilename);
                                if (!isOpened) {
                                    clearInterval(interval);
                                    uploadFilename = uploadFilename + '' + (Math.floor(chatTime) + 500) + '.spx';
                                    uploadFileToOSS(voiceFilename, uploadFilename, function (url) {
                                        network.send(3008, {room_id: gameData.roomId, type: 'voice', content: url});
                                    }, function () {
                                        console.log('upload fail');
                                    });
                                }
                            };
                            interval = setInterval(checkFunc, 32);
                        } else {
                            animNode = ccs.load(majiang_hn.res.ChatErrorNode_json).node;
                            animNode.setPosition(that.getContentSize().width / 2, that.getContentSize().height / 2);
                            animNode.runAction(cc.sequence(cc.delayTime(1), cc.callFunc(function () {
                                animNode.removeFromParent();
                                animNode = null;
                            })));
                            that.addChild(animNode);
                            stopVoiceRecord(voiceFilename);
                        }
                    }
                    else
                        stopVoiceRecord(voiceFilename);
                }
            });
        },
        showArrow: function (pai, row) {
            var that = this;
            this.hideArrow();
            var arrow = pai.getParent().getChildByName('arrow');
            if (!arrow) {
                arrow = new cc.Sprite(majiang_hn.res.PaiUnit_arrow);
                arrow.setAnchorPoint(0.5, 0);
                arrow.setName('arrow');
                arrow.setLocalZOrder(100);
                pai.getParent().addChild(arrow);
                arrow.setScale(pai.getScale());
                var duration = 0.8;
                arrow.setOpacity(168);
            }
            arrow.setVisible(true);
            var arrowrot = [180, 270, 0, 90];
            if (row == 0) {
                arrow.setPosition(pai.getPosition().x, pai.getPosition().y - 35);
            }
            else if (row == 1) {
                arrow.setPosition(pai.getPosition().x - 40, pai.getPosition().y + 10);
            }
            else if (row == 2) {
                arrow.setPosition(pai.getPosition().x, pai.getPosition().y + 35);
            }
            else if (row == 3) {
                arrow.setPosition(pai.getPosition().x + 25, pai.getPosition().y + 5);
            }

            arrow.setRotation(arrowrot[row]);
            if (row == 0 || row == 2) {
                arrow.runAction(cc.sequence(cc.spawn(cc.moveBy(duration, 0, +16), cc.fadeTo(duration, 255))
                    , cc.spawn(cc.moveBy(duration, 0, -16), cc.fadeTo(duration, 168))).repeatForever());
            }
            else if (row == 1 || row == 3) {
                arrow.runAction(cc.sequence(cc.spawn(cc.moveBy(duration, +16, 0), cc.fadeTo(duration, 255))
                    , cc.spawn(cc.moveBy(duration, -16, 0), cc.fadeTo(duration, 168))).repeatForever());
            }
        },
        setLiang: function (liang) {
            var that = this;
            that.lianging = liang;
            return;
            var that = this;
            if (liang) {
                that.lianging = true;
                for (var i = 0; i < 14; i++) {
                    var pai = that.getPai(2, i);
                    if (pai.paiId) {
                        pai.isLiang = false;
                        Filter.grayMask(pai);
                    }
                }
                that.$('btn_queding').setVisible(true);
                that.$('btn_quxiao').setVisible(true);
            }
            else {
                that.$('btn_queding').setVisible(false);
                that.$('btn_quxiao').setVisible(false);
                that.hideTip();
                that.lianging = false;
            }
        },
        showTip: function (content, isShake) {
            var that = this;
            isShake = _.isUndefined(isShake) ? true : isShake;
            var scale9sprite = that.$('top_tip');
            if (!(scale9sprite instanceof cc.Scale9Sprite)) {
                var newScale9sprite = new cc.Scale9Sprite(majiang_hn.res.round_rect_91, cc.rect(0, 0, 91, 32), cc.rect(46, 16, 1, 1));
                newScale9sprite.setName('top_tip');
                scale9sprite.setAnchorPoint(0.5, 0.5);
                newScale9sprite.setPosition(scale9sprite.getPosition());
                scale9sprite.getParent().addChild(newScale9sprite);
                var lb = that.$('top_tip.lb_tip');

                text = new ccui.Text();
                text.setName('lb_tip');
                text.setFontSize(lb.getFontSize());
                text.setTextColor(lb.getTextColor());
                text.enableOutline(cc.color(38, 38, 38), 1);
                newScale9sprite.addChild(text);

                lb.removeFromParent(true);
                scale9sprite.removeFromParent(true);
                scale9sprite = newScale9sprite;
            }
            var text = that.$('top_tip.lb_tip');
            text.setString(content);
            var size = cc.size(text.getVirtualRendererSize().width + 35, scale9sprite.getContentSize().height);
            text.setPosition((text.getVirtualRendererSize().width + 35) / 2, scale9sprite.getContentSize().height / 2);
            scale9sprite.setContentSize(size);
            scale9sprite.setScale(1.2);
            scale9sprite.setVisible(true);
            if (isShake)
                scale9sprite.runAction(cc.sequence(cc.scaleTo(0.2, 1.4), cc.scaleTo(0.2, 1.2)));
        },
        hideTip: function () {
            var that = this;
            if (!that.isReplay)
                that.$('top_tip').setVisible(false);
        },
        hideArrow: function () {
            var that = this;
            for (var i = 0; i < 4; i++) {
                var arrow = that.$('row' + i + '.c0.arrow');
                if (arrow)
                    arrow.removeFromParent(true);
            }
        },
        liangAllPai: function () {
            var that = this;
            for (var i = 0; i < 14; i++) {
                var pai = this.getPai(2, i);
                if (pai.paiId) {
                    pai.isLiang = true;
                    Filter.remove(pai);
                }
            }
        },
        selectHideGangCb: function () {
            var that = this;
            network.send(4015, {room_id: gameData.roomId, hided_gang_arr: that.hidedGangArr});
        },
        throwDice: function (title, dice, paiIdA, paiIdB, cb) {
            var that = this;
            title = title || '';
            if (dice < 1 || dice > 6)
                return;
            network.stop();
            showWindow('Ma_ThrowDiceWindow', that, title, dice, paiIdA, paiIdB, cb);
        },
        chiLayerCallback: function (paiId, oriPaiId) {
            var that = this;
            if (that.chiPengGangHuCode == 4052) {
                network.send(4056, {
                    room_id: gameData.roomId,
                    pai_id: paiId,
                    ori_pai_id: oriPaiId,
                    op: that.opType.OP_CHI
                });
                if (that._Ma_KaiGangWindow) {
                    that._Ma_KaiGangWindow.removeFromParent(true);
                    that._Ma_KaiGangWindow = null;
                }
            } else {
                that.hideChiPengGangHu();
                that.sendChiPengGang(that.opType.OP_CHI, 2, paiId, oriPaiId);
            }
            that._chiPengGangHuCode = 0;
        },
        showChiLayer: function (paiId) {
            var that = this;
            var paiArr = that.getPaiArr();
            paiArr.push(paiId);
            var arr = [
                [paiId - 2, paiId - 1, paiId],
                [paiId - 1, paiId, paiId + 1],
                [paiId, paiId + 1, paiId + 2]
            ];
            var posibleIdxArr = [];
            for (var i = 0; i < arr.length; i++) {
                var a = arr[i][0];
                var b = arr[i][1];
                var c = arr[i][2];
                if (isSameColor(a, b) && isSameColor(a, c) &&
                    paiArr.indexOf(a) >= 0 && paiArr.indexOf(b) >= 0 && paiArr.indexOf(c) >= 0)
                    posibleIdxArr.push(i);
            }
            if (posibleIdxArr.length == 1) {
                that.chiLayerCallback(arr[posibleIdxArr[0]][1], paiId);
                that.hideChiPengGangHu();
            }
            else if (posibleIdxArr.length > 1) {
                showWindow('Ma_ChiPaiWindow', arr, posibleIdxArr, paiId, that.chiLayerCallback.bind(that), that);
            }
        },
        playEffect: function (filename, sex) {
            var that = this;
            playEffect(filename, sex);
        },
        setHuTipVisible: function (visible) {
            var that = this;
            for (var i = 0; i < 14; i++) {
                var cardSprite = this.getPai(2, i);
                if (cardSprite.getChildByName('hucardSprite')) {
                    cardSprite.getChildByName('hucardSprite').stopAllActions();
                    cardSprite.getChildByName('hucardSprite').setVisible(visible);
                }
            }
        },
        HuCardTip: function (showdata, posx, isVisible) {
            var that = this;
            var hupaitip = that.getChildByName('hupaitip');
            if (!isVisible && hupaitip) {
                hupaitip.setVisible(isVisible);
                return;
            }
            if (showdata == null) {
                for (var i = 0; i < 14; i++) {
                    var pai = this.getPai(2, i);
                    pai.hucards = null;
                }
                return;
            }
            var tiplength = showdata.length;

            var hupaitipW = 150;//大的背景
            var hupaitipH = 160;//大的背景
            var hupaitip2W = 140;//小的背景宽
            var hupaitip2H = 100;//小的背景高

            if (hupaitip) {
                hupaitip.setVisible(true);
                hupaitip.setContentSize(cc.size(hupaitipW + (hupaitip2W + 10) * tiplength, hupaitipH));
                //设置位置
                posx = posx + 40;
                if (posx + hupaitip.getContentSize().width / 2 > that.getContentSize().width) {
                    posx = that.getContentSize().width - hupaitip.getContentSize().width / 2 - 20;
                } else if (posx - hupaitip.getContentSize().width / 2 < 0) {
                    posx = hupaitip.getContentSize().width / 2 + 20;
                }
                hupaitip.setPositionX(posx);
                for (var i = 0; i < 9; i++) {
                    var card = hupaitip.getChildByName('card' + (i + 1));
                    var fantext = hupaitip.getChildByName('fantext' + (i + 1));
                    var fannum = hupaitip.getChildByName('fannum' + (i + 1));
                    var zhangtext = hupaitip.getChildByName('zhangtext' + (i + 1));
                    var zhangnum = hupaitip.getChildByName('zhangnum' + (i + 1));
                    if (tiplength > i) {
                        //card
                        card.setVisible(true);
                        var paiName = that.getPaiNameByRowAndId(2, showdata[i][0], true, true);
                        that.setSpriteFrameByName(card, paiName, 'pai');
                        card.setPosition(cc.p(10 + (hupaitip2W + 10) * (i + 1), hupaitip.getContentSize().height / 2));
                        fantext.setVisible(true);
                        fantext.setPosition(cc.p(80 + (hupaitip2W + 10) * (i + 1), hupaitipH * 0.6));
                        fannum.setVisible(true);
                        fannum.setPosition(cc.p(60 + (hupaitip2W + 10) * (i + 1), hupaitipH * 0.6));
                        fannum.setString(showdata[i][1]);
                        zhangtext.setVisible(true);
                        zhangtext.setPosition(cc.p(80 + (hupaitip2W + 10) * (i + 1), hupaitipH * 0.4));
                        zhangnum.setVisible(true);
                        zhangnum.setString(showdata[i][2]);
                        zhangnum.setPosition(cc.p(60 + (hupaitip2W + 10) * (i + 1), hupaitipH * 0.4));
                    } else {
                        card.setVisible(false);
                        fantext.setVisible(false);
                        fannum.setVisible(false);
                        zhangtext.setVisible(false);
                        zhangnum.setVisible(false);
                    }
                }
            } else {
                var hupaitip = new cc.Scale9Sprite(majiang_hn.res.PaiUnit_toast_bg, null, cc.rect(50, 50, 50, 50));
                hupaitip.setName('hupaitip');
                hupaitip.setAnchorPoint(cc.p(0.5, 0));
                hupaitip.setContentSize(cc.size(hupaitipW + (hupaitip2W + 10) * tiplength, hupaitipH));
                hupaitip.setPosition(cc.p(that.getContentSize().width - 20, 172));
                that.addChild(hupaitip);
                //设置位置
                posx = posx + 40;
                if (posx + hupaitip.getContentSize().width / 2 > that.getContentSize().width) {
                    posx = that.getContentSize().width - hupaitip.getContentSize().width / 2 - 20;
                } else if (posx - hupaitip.getContentSize().width / 2 < 0) {
                    posx = hupaitip.getContentSize().width / 2 + 20;
                }
                hupaitip.setPositionX(posx);

                var huSprite = new cc.Sprite(majiang_hn.res.PaiUnit_hupaitip_hu);
                huSprite.setPosition(cc.p(70, hupaitip.getContentSize().height / 2));
                hupaitip.addChild(huSprite);
                for (var i = 0; i < 9; i++) {
                    //card
                    var card = new cc.Sprite();
                    card.setScale(0.88);
                    card.setName('card' + (i + 1));
                    card.setPosition(cc.p(10 + (hupaitip2W + 10) * (i + 1), hupaitip.getContentSize().height / 2));
                    hupaitip.addChild(card);

                    var fantext = new ccui.Text();
                    fantext.setString('番');
                    fantext.setName('fantext' + (i + 1));
                    fantext.setFontSize(20);
                    fantext.setTextColor(cc.color(0, 255, 0));
                    fantext.enableOutline(cc.color(38, 38, 38), 1);
                    fantext.setPosition(cc.p(80 + (hupaitip2W + 10) * (i + 1), hupaitipH * 0.6));
                    hupaitip.addChild(fantext);
                    var fannum = new ccui.Text();
                    fannum.setName('fannum' + (i + 1));
                    fannum.setFontSize(20);
                    fannum.setTextColor(cc.color(255, 255, 0));
                    fannum.enableOutline(cc.color(38, 38, 38), 1);
                    fannum.setPosition(cc.p(60 + (hupaitip2W + 10) * (i + 1), hupaitipH * 0.6));
                    hupaitip.addChild(fannum);
                    var zhangtext = new ccui.Text();
                    zhangtext.setString('张');
                    zhangtext.setName('zhangtext' + (i + 1));
                    zhangtext.setFontSize(20);
                    zhangtext.setTextColor(cc.color(0, 255, 0));
                    zhangtext.enableOutline(cc.color(38, 38, 38), 1);
                    zhangtext.setPosition(cc.p(80 + (hupaitip2W + 10) * (i + 1), hupaitipH * 0.4));
                    hupaitip.addChild(zhangtext);
                    var zhangnum = new ccui.Text();
                    zhangnum.setName('zhangnum' + (i + 1));
                    zhangnum.setFontSize(20);
                    zhangnum.setTextColor(cc.color(255, 255, 0));
                    zhangnum.enableOutline(cc.color(38, 38, 38), 1);
                    zhangnum.setPosition(cc.p(60 + (hupaitip2W + 10) * (i + 1), hupaitipH * 0.4));
                    hupaitip.addChild(zhangnum);
                    if (tiplength > i) {
                        card.setVisible(true);
                        var paiName = that.getPaiNameByRowAndId(2, showdata[i][0], true, true);
                        that.setSpriteFrameByName(card, paiName, 'pai');
                        fantext.setVisible(true);
                        fannum.setVisible(true);
                        fannum.setString(showdata[i][1]);
                        zhangtext.setVisible(true);
                        zhangnum.setVisible(true);
                        zhangnum.setString(showdata[i][2]);
                    } else {
                        card.setVisible(false);
                        fantext.setVisible(false);
                        fannum.setVisible(false);
                        zhangtext.setVisible(false);
                        zhangnum.setVisible(false);
                    }
                }
            }
        },
        changeBtnStatus: function () {
            var that = this;
            that.$('btn_bg').setVisible(!that.$('btn_bg').isVisible());
            //that.$('btn_control_btns').setFlippedY(!that.$('btn_control_btns').isFlippedY());
        },
        hideControlBtns: function () {
            var that = this;
            that.$('btn_bg').setVisible(false);
            //that.$('btn_control_btns').setFlippedY(true);
        },
        getRowByUid: function (uid) {
            var that = this;
            return that.uid2position[uid];
        },
        getOriginalPos: function () {
            var that = this;
            return 2;
        },
        getEffectEmojiPos: function (caster, patient, isNotMid) {
            var that = this;
            var pos = {};
            var infoCaster = that.$("info" + caster);
            pos[caster] = infoCaster ? infoCaster.convertToWorldSpace(that.$("info" + caster + ".head").getPosition()) : cc.p(cc.winSize.width / 2, cc.winSize.height / 2);
            var infoPatient = that.$("info" + patient);
            pos[patient] = (patient != that.getOriginalPos() && infoPatient) || isNotMid ? infoPatient.convertToWorldSpace(that.$("info" + patient + ".head").getPosition()) : cc.p(cc.winSize.width / 2, cc.winSize.height / 2);
            return pos;
        },
        getChatInfoNode: function (idx) {
            var that = this;
            var ChatInfoNode = null;
            if (that.$("info" + idx))
                ChatInfoNode = that.$("info" + idx + '.ChatInfo');
            return ChatInfoNode;
        }
    });
})(window);
